S
sergio.calleja
Hi Everybody,
i need to restart a windows service made with c# when an fixed event is
raised.
So to test it, I've added a servicecontroller to my service, and in the
creation method, i've created a new thread to try to stop it.
This is my code:
public Service1()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
log = new EventLog("Application", ".", "ServiceTest");
_timer = new Timer(new TimerCallback(OnTimer), null, 20000,0);
}
private void OnTimer(object state)
{
try
{
log.WriteEntry("Timer");
serviceController1.Stop();
log.WriteEntry("Stopping");
serviceController1.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped);
log.WriteEntry("starting");
serviceController1.Start();
log.WriteEntry("Restarted");
}
catch (Exception ex)
{
log.WriteEntry(ex.ToString());
}
}
When service is stopped it doesn't start again, what's the problem? Can
you help me?
Thanks!
i need to restart a windows service made with c# when an fixed event is
raised.
So to test it, I've added a servicecontroller to my service, and in the
creation method, i've created a new thread to try to stop it.
This is my code:
public Service1()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
log = new EventLog("Application", ".", "ServiceTest");
_timer = new Timer(new TimerCallback(OnTimer), null, 20000,0);
}
private void OnTimer(object state)
{
try
{
log.WriteEntry("Timer");
serviceController1.Stop();
log.WriteEntry("Stopping");
serviceController1.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped);
log.WriteEntry("starting");
serviceController1.Start();
log.WriteEntry("Restarted");
}
catch (Exception ex)
{
log.WriteEntry(ex.ToString());
}
}
When service is stopped it doesn't start again, what's the problem? Can
you help me?
Thanks!