1
Answer

Thread Pool with windows service

carl_sargunar

carl_sargunar

15y
24.7k
1
Hi

I was wondering the best way to implement a multi threaded windows service, to be used in similar fashion to the windows task scheduler service with added functionality.

Does anybody know of any resources or can anybody point me inthe right direction. I so far plan to have a main thread running as part of a threadpool, and each time I need to start a new task, start a new thread and add it to the thread pool. I assume then the task has finished, the thread will automatically stop and be removed from the threadpool.

Stopping the service will stop any subsequent threads from starting, using simple bool flags, but not stop any threads already running from finishing

Pseudocode would be something like this

Thread main = new thread()
Bool running;

OnStart()
{
running = true;
main.threadstart = MainThreadWorker;
main.start;
}

OnStop() { running = false; }

MainThreadWorker()
{
while (running)
{
If (new task)
  {
  Start New thread;
  Add new thread to Threadpool;
  }

  if (running) {mainthread.sleep (Some interval)}
}
Somehow kill the threadpool here;
}


thanks for your help
Answers (1)