开发者

Queued execution of threads in c#

开发者 https://www.devze.com 2023-02-04 01:35 出处:网络
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 th

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消