Sorry this question is not very clear, if I know the correct words to describe the problem, Google would be likely to come up with the answer.
I am looking for a queue class that:
- Lets any number of threads put an item on the queue
- Items are processed in the order they are added to the queue
- I don’t mind what thread process an item
- Only one item is processed at a time.
- I rather not have a thread blocked waiting for an item to be added to the queue if there are no items on the queue.
- The normal case is for the queue to be empty most of the time.
e.g Just like what happens with a BeginInvoke on a WinForms windows… (Or PostMessage if you have every done raw win32 programming)
We are using .net 3.5
I am looking for something ready-made in the .net framework, or a open source project that has good unit tests, as I don’t wish to have to write all the unit tests for a home-make solution.
For background, see Why are my message be processed out of order over a single WCF TCP channel (with ConcurrencyMode.Reentrant)? by using this depatcher I was able to change to using ConcurrencyMode.Single and still advoid deadlocks.
Here’s a sketch of a class that can do that:
Applications would use it like this:
It would probably be useful to let applications stop the processing as well, probably by adding a flag that
ProcessWorkcould check after each item is dequeued, but it’s not clear what to do with unprocessed items (perhaps it would be enough to allow access to them and let the caller decide).