Thread-safe blocking queue implementation on .NET

后端 未结 7 781
無奈伤痛
無奈伤痛 2020-12-15 07:28

I\'m looking for an implementation of thread-safe blocking queue for .NET. By \"thread-safe blocking queue\" I mean: - thread-safe access to a queue where Dequeue method cal

7条回答
  •  时光取名叫无心
    2020-12-15 07:46

    The Microsoft example is a good one but it is not encapsulated into a class. Also, it requires that the consumer thread is running in the MTA (because of the WaitAny call). There are some cases in which you may need to run in an STA (e.g., if you are doing COM interop). In these cases, WaitAny cannot be used.

    I have a simple blocking queue class that overcomes this issue here: http://element533.blogspot.com/2010/01/stoppable-blocking-queue-for-net.html

提交回复
热议问题