Queued execution of threads in c#
I have a windows service which executes a job asynchronously every few minutes, sometimes the windows service executes and the previous job has not finished, using threading is there a way to queue the ne开发者_如何学Gow job if the previous one hasnt finished so that it starts running when the first job finishes?
You could create your own producer/consumer queue of jobs - effectively a single-thread threadpool.
This is easy to do in .NET 4 using BlockingCollection<T>
; before then it's a little trickier, but not too bad.
you have to implement the queue in main controlling service. on the completion of thread and/or periodicaly you can check queue and start next task.
精彩评论