Using Thread.Sleep() in a Windows Service

后端 未结 5 1016
萌比男神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 07:48

    I would use a timer, Thread.Sleep, could cause a blocking piece that could prevent the service from shutting down.

    If the interval is that wide spread, and regular, you might just schedule it as well. But if you are talking about long, non-consistent intervals, then yes a Timer would be better.

提交回复
热议问题