Building a Windows Service that periodically runs.

Here is some code I threw together to create a windows service that gets called periodically. To use it you’ll have to add this code into the Service class and create an application setting called PollingTime to contain the amount of time between calls of the process.

Also note that if the process is still executing then it will block and not run again until the process has been completed. It’s using the _executing variable with the Interlock to make sure this happens. To learn more about Interlocked variables you can go here.

Mike GriffithBuilding a Windows Service that periodically runs.