I have a Windows service which triggers a thread on OnStart(string[] args)
. There are other threads created by this main thread. After installing and starting the service, when I try to stop the service I am unable to stop the service during the first attempt. When I right click on my service and request 'Stop'. I get the below exception and the service is still running.
Windows could not stop the service on Local Computer. The service did not return error. This could be an internal windows error or an internal service error. If the problem persists, contact your system administrator.
When I try to stop it again, I end up with other message as
Windows could not stop the service on Local computer.
Error 1061: The service cannot accept control messages at this time.
but service is stopped. So I am performing right click -> Stop, twice to stop a service.
I tried to abort thread and stop the service as below but no gain.
protected override void OnStop()
{
onStartThread.Abort();
Log.AuditEventLogger("Service Stopped");
this.Stop();
}
I highly appreciate any suggestions. Thank you.