Quantcast
Channel: Directory Services forum
Viewing all articles
Browse latest Browse all 31638

What to do with a worker thread in the OnStop method in a basic Windows service?

$
0
0
Hi

I have a basic Windows service which performs some tasks, which are executed periodically in an endless loop: "ExecuteServiceWorkerMethods()".
I am starting the endless loop via a worker thread from the OnStart() method as below:

OnStart(string[] args)
{
       workerThread = new Thread(ExecuteServiceWorkerMethods);
       workerThread.Name = "ServiceWorkerThread";
       workerThread.IsBackground = false;
       workerThread.Start();
}

Now I am wondering what to do with the worker thread in the OnStop() method?

My endless loop looks like this:

private void ExecuteServiceWorkerMethods()
{
      while (!serviceStopped)
      {

DO WORK....

          while (servicePaused)
          {
              Thread.Sleep(sleepTimeMillisecondsWhileServicePaused);
          }
 Thread.Sleep(sleepTimeMillisecondsWhileServiceNotStopped);
      }
}

Remember this is all very basic. I just want to be able to start and stop my Windows service.

Viewing all articles
Browse latest Browse all 31638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>