Forums - C# Corner

Forum guidelines

Thread Pool with windows service

Aug 14 2008 10:26 AM

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;

running = true;
main.threadstart = MainThreadWorker;

OnStop() { running = false; }

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)

File APIs for .NET – 25% off Aspose.Total
Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more! Use coupon code HOL2016PSB