tags:

views:

22

answers:

2

I've written a nice priority queue class,

class ConcurrentPriorityQueue<T> 
    : IProducerConsumerCollection<KeyValuePair<int,T>>, INotifyCollectionChanged
    where T : INotifyPropertyChanged

which I now want to wrap in a in a BlockingCollection,

Queue = new ConcurrentPriorityQueue<DownloadItem>(10);
Buffer = new BlockingCollection<KeyValuePair<int, DownloadItem>>(Queue, 1000)
    {
        new KeyValuePair<int, DownloadItem>(0, new DownloadItem{Url = "stackoverflow.com"})
    };

So that it can add a maximum capacity, and hopefully some thread-safety. Now, however, I seem to have lost the observable functionality!

How can I hook a DataGrid up to this collection so it still receive the collection changed notifications?

A: 

BlockingCollection does not implement INotifyCollectionChanged interface that is essential for data binding (AFAIK). Looks like you have to roll up your own implementation (either inheriting from blocking collection or encapsulating it) that implements the said interface.

VinayC
Don't think I do actually... I just have to bind to the underlying collection instead.
Mark
A: 

Binding to the underlying collection (the priority queue) seems to work. Then I just call Add and Take on the blocking collection instead. I guess that's why they decided to keep the objects separate.

Mark