I'm writing a program where one thread needs to push items onto the queue, and one or more threads pops items off the queue and processes them. To avoid running out of memory, I'd like the producer thread to sleep when the queue gets full. Some items have a higher priority than others, so I'd like those to be processed first. If the items have the same priority, I'd like the one that was added first to be processed first.
I want to display the top 100 items or so in a WPF DataGrid, so it needs to be accessed by a UI thread as well. Would be nice if it could notify the UI thread that there's been an update as well, i.e., implements IObservable.
Is there a container class that will do all this?
For bonus points, I'm pretty sure the entire queue doesn't need to be locked both when enqueing and dequeing.
.NET 4 implementations are fine.