I have created a service, where I am sending commands to the service via MSMQ.
Now I need to restart the service but when it reaches to the stop command it just throws error or it is not able to read the next line as the service performing this task stops.
The code I am using is :
ServiceController service = new ServiceController(serviceName);
try
{
int millisec1 = Environment.TickCount;
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
ShutdownService(serviceName, timeoutMilliseconds);
// count the rest of the timeout
int millisec2 = Environment.TickCount;
timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds - (millisec2 - millisec1));
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch (Exception ex)
{
s_log.Error(ex);
}
How can I restart service by itself as logically when the service will stop, it will not execute next line of code.