Service question in c# .Net 2.0 framework

  • Thread starter Thread starter Guest
  • Start date Start date
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
}
}
}
 
Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top