If you cannot write a window service, you will simplify your life - there may be more efficient tasks. Windows services are best used for things where there is some constant background activity that should happen - not to run tasks for a long time.
However, if you must do this with a Windows service, then you do not want to set a timer wait timeout. This is the most definitely problematic approach. What happens if your application restarts? How does he know how long he sleeps? Or what if the thread is reloaded?
The best approach is to write a record somewhere in the database that identifies when the next import should occur as a date / time. The Windows service may wake up periodically (every few minutes or hours) and see if the current date / time exceeds this value. If so, start the import and update the next launch date in the database until the next launch.
If your application is restarted, you simply read the value from the database and continue as before.
source share