public void CheckStatus(string ServiceName) { ServiceController sc = new ServiceController(ServiceName); var Service_ctrl = ServiceController.GetServices().FirstOrDefault(s => s.ServiceName == ServiceName); //Console.WriteLine(Service_ctrl.Status); if (Service_ctrl != null) { if ((Service_ctrl.Status != ServiceControllerStatus.Running) && (OnServiceStatusChange != null)) { ServiceChangeStatus serviceChangeStatus = new ServiceChangeStatus(ServiceName, Service_ctrl.Status); ServicechangeEventArgs servicechangeEventArgs = new ServicechangeEventArgs(serviceChangeStatus); OnServiceStatusChange(servicechangeEventArgs); } } else { //Service not Available } }
public ServicechangeEventArgs(ServiceChangeStatus serviceChangeStatus) { this._ServiceChangeStatus = serviceChangeStatus; }