I have a application that has a GUI where you can do some settings. One of the settings is to set the time when a data collection from various sources will run. The windows service that does the actual work is right now running a thread that sleeps until the time that has been set occurs.
Question
My question is this, once my service is sleeping and someone decides to change the time for when the data collection should occur, what is the best way to notify the service of the changed time?
Is it possible from my GUI part to tell windows to restart my specific services? Or can I send it an thread interrupt? How would you do it?
Your GUI can certainly control the service, provided the account it is running under has the right privileges.
You can use the
ServiceControllerclass for this:Another option, assuming the settings are stored in a file is to use the
FileSystemWatcherclass to monitor changes to the file – this will allow you to see if the values changed and reset them in the service.