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