System.Collections.Concurrent has several new collections that work very well in multi-threaded environments. However, they are a bit limited. Either they are blocked until the element becomes available, or they return default(T) (TryXXX methods).
I need a collection that is thread safe, but instead of blocking the calling thread, it uses a callback to tell me that at least one item is available.
My current solution is to use a BlockingCollection, but use APM with a delegate to get the next element. In other words, I create a delegate for the method that Take from the collection and executes that delegate using BeginInvoke .
Unfortunately, for this I have to support many states in my class. Worse, the class is not thread safe; It can only be used by one thread. I will bypass the maintainability edge, which I would rather not do.
I know that there are some libraries that do what I am doing here quite simply (I believe that the Reactive Framework is one of them), but I would like to achieve my goals without adding any links outside of version 4 of the structure.
Are there any better templates that I can use that don't require external links that achieve my goal?
TL; DR:
Are there templates that satisfy the requirement:
"I need to tell the collection that I am ready for the next item, and for the collection to call back when this next item arrives, without locking the threads."
collections multithreading c # nonblocking
Will
source share