I am going to create a system service in C#.
In the onstart section I would like to loop every 30 seconds and query a mysql database. If numrows are greater than 0 I will process some faxes using the faxcom library.
My question is: Would looping every 30 seconds exhaust the program/computer? What would be the best function/method to use for the loop and sleep? Do you have any example code for the loop and sleep?
Using
Thread.Sleep()would be a bad solution, because even while sleeping your thread is active. UseTimerclass instead and handle itsElapsedevent.This article examines different ways to tackle the periodical execution of your service.
Here is what your OnStart method might look like: