G
Guest
I am looking for a way to cleanly stop my service in the event of an error.
Within the worker thread, if an unrecoverable error is caught, I would like
to stop my service. Exiting the worker thread doesn't seem to do it. Using
the SCM to stop the service doesn't feel right. Am I missing something? My
service looks like (unrunnable example code below):
public partial class MyService : ServiceBase
{
protected override void OnStart(string[] args)
{
ListenerWorkerThread = new Thread(new ThreadStart(PortListener));
ListenerWorkerThread.Start();
}
protected void PortListener()
{
try
{
//do some work
}
catch (Exception ex) //some really bad error
{
//Write it to the log and stop the service cleanly
}
}
}
Within the worker thread, if an unrecoverable error is caught, I would like
to stop my service. Exiting the worker thread doesn't seem to do it. Using
the SCM to stop the service doesn't feel right. Am I missing something? My
service looks like (unrunnable example code below):
public partial class MyService : ServiceBase
{
protected override void OnStart(string[] args)
{
ListenerWorkerThread = new Thread(new ThreadStart(PortListener));
ListenerWorkerThread.Start();
}
protected void PortListener()
{
try
{
//do some work
}
catch (Exception ex) //some really bad error
{
//Write it to the log and stop the service cleanly
}
}
}