Reputation: 282885
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?
Upvotes: 2
Views: 1899
Reputation: 282885
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.
Upvotes: 1
Reputation: 49195
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.
Upvotes: 0