且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

c#阻塞收集和线程

更新时间:2023-01-23 18:07:40

这个解决方案是否合适

Is this solution appropriate

基本上,是的.这是生产者/消费者的情况,而这正是 BlockingCollection 的用途.

Basically, yes. It is a Producer/Consumer situation and that's precisely what the BlockingCollection is for.

这有什么问题吗?

您必须非常确定 doSomeBackgroundWork() 就您的 doWork() 代码而言是线程安全的.

You have to be very sure that the doSomeBackgroundWork() is thread-safe with respect to your doWork() code.

根据可以推送多少 myEventArgs,为您的阻塞集合设置上限可能是个好主意.

It might be a good idea to put a ceiling on Your blockingcollection, dependng on how many myEventArgs can be pushed.