Hello everyone! From win service i start console application using service command. When the application is started it should stop the service it runs and replace some dll from the service. To stop service i use something like this
public void StopService(string serviceName, int timeoutMilliseconds) { var service = new ServiceController(serviceName); try { if (service.Status == ServiceControllerStatus.Running) { TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds); service.Stop(); service.WaitForStatus(ServiceControllerStatus.Stopped, timeout); ShowToLogFile("Сервис " + serviceName + " остановлен"); } } catch (Exception ex) { ShowToLogFile(ex.message); } }
StopService(ServiceName, 5000);
but then the application try to stop it generate an error Time out has expired and the operation has not been completed. Its stops too long or i do something wrong ?