C # Round Robin common loop (split / sorted)

I often have to process an element queue, where no user should block the queue, and the elements in the queue should be processed in some order. I often write a class for this, but I thought there should be some kind of general version, but I can not find it.

So I'm looking for a queue class where I can specify a type, a selector for sections, and a selector to order so that I can add objects to the queue, and then when I return the objects, I get the first object from the next section, ordered by my qualifier order.

For example, I would call it that to indicate how to split and how to sort the queue:

var queue = new RoundRobinQueue<Message>( _ => _.UserID, _ => _.SendDate ); 

And after I added a lot of messages, I can Parallel.ForEach elements in my queue and process them in the order of the early SendDate for the next User . Thus, if one user is slow, his elements will not block the queue, since he receives only one thread, but if there is only one user, he is the only section, so he receives all the threads.

I looked through everything, but could not find a good general implementation in C # for this. Any ideas?

+6
source share
1 answer

Look at the classes defined in System.Collections.Concurrent . There is a common ConcurrentQueue, as well as more basic building blocks for consumer-producer models.

Available classes and interfaces are summarized on MSDN .

-1
source

All Articles