The MSDN documentation on Windows Services is really good and has everything you need to get started.
The problem you are facing is related to your OnStart implementation, which should only be used to configure the service so that it is ready to start, the method should immediately return. Usually you run the bulk of the code in another thread or timer. Check the OnStart page for confirmation.
Edit: Not knowing what your Windows service will do, it's hard to say how to implement it, but let me say that you want to run the method every 10 seconds while the service is running:
public partial class Service1 : ServiceBase { private System.Timers.Timer _timer; public Service1() { InitializeComponent(); } protected override void OnStart(string[] args) { #if DEBUG System.Diagnostics.Debugger.Launch();
Here, the OnStart method returns immediately after setting the timer, and TimerOnElapsed will be executed in the TimerOnElapsed . I also added a call to System.Diagnostics.Debugger.Launch(); which will facilitate debugging.
If you have other requirements, edit your question or post a comment.
Chriso
source share