Using Thread.Sleep() in a Windows Service

后端 未结 5 1106
萌比男神i
萌比男神i 2021-02-04 07:46

I\'m writing a windows service that needs to sleep for long periods of time (15 hrs is the longest it will sleep, 30 mins is the shortest). I\'m currently using Thread.

5条回答
  •  青春惊慌失措
    2021-02-04 08:10

    Another thing to consider is that threads are finite resources and each thread consumes a portion of memory (1MB?) for the its stack. They may also increase load for the scheduler.

    Now, if your service isn't doing much else the wasted space is trivial, but it is wise to be aware of this before you start allocating multiple threads. Using a ThreadPool and/or Timers is much more efficient.

提交回复
热议问题