Using Thread.Sleep() in a Windows Service

后端 未结 5 1003
萌比男神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:54

    It's generally regarded as bad practice to use Thread.Sleep() in a lot of cases.

    If you want the service to run in the background, you should use a timer.

    If the service only needs to be run at scheduled intervals, I'd recommend you look into using Windows task scheduler to allow Windows to run the application when you need it to.

提交回复
热议问题