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:
MyClass.Start();
This method runs a while loop and exits only on failure.
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.
Otherwise, when my method breaks quickly (for example, some parameters are missing), service reports a "Running" state, but the method has exited.
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)?