C# Timer vs Thread in Service

前端 未结 4 2138
灰色年华
灰色年华 2021-02-09 05:56

I have a Service that hits a database every 10 sec and gets the data if there is any. The thing is that processing this data can take up to 30 sec. If I use a Timer with 10 sec

4条回答
  •  故里飘歌
    2021-02-09 06:53

    There is nothing wrong with this approach. A sleeping thread does not consume any CPU cycles.

    If you need to do something exactly every X seconds, a timer is the way to go. If, on the other hand, you want to pause for X seconds, then Thread.Sleep is appropriate.

提交回复
热议问题