Service question in c# .Net 2.0 framework

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
}
}
}
 
K

Kevin Yu [MSFT]

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."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top