As noted in every other answer, it looks like it should be an executable or script that you run as a scheduled task.
However, if for some reason you are required to work as a Windows service and work in .NET, you just need to call the Stop() method inherited from ServiceBase as soon as your service finishes its work. From the MSDN documentation for the method:
The Stop method sets the state of the service to indicate that a stop is pending and calls the OnStop method. After the application is stopped, the service state is stopped. If the application is a hosted service, the application domain is unloaded.
There is one important caveat: the user account under which the service runs must have permission to stop the services (this is the topic for ServerFault ).
As soon as the OnStart service method is completed, it will continue to work (do nothing) until something tells it to stop in one of the following ways:
- Programmatically, calling
Stop inside the service itself or from an external process using the method Colin Gravil describes in his answer . - Through the command line.
- From the Management console in the Windows Management console.
Jeff sternal
source share