title: How to program windows service app to report the right status?
body: <p>I know that windows service application in C# provides methods like OnStart() and OnStop(). For example I say that I have written a method in a previous program and i call it in method OnStart() of the service:</p>
  
  <p>MyClass.Start();</p>
  
  <p>This method runs a while loop and exits only on failure.</p>
  
  <p>Problem is, when this method with loop inside is executed in OnStart() method and I start service in Windows, service reports status "Starting", and after some time exits, so the service is never reported that has started.</p>
  
  <p>Otherwise, when my method breaks quickly (for example, some parameters are missing), service reports a "Running" state, but the method has exited.</p>
  
  <p>My question is how can I program Windows service to report "Running" state while my method is running, and stop the service when method exits (exception)?</p>