gpt4 book ai didi

c# - 如何使 BlockingCollection 可观察?

转载 作者:太空宇宙 更新时间:2023-11-03 14:26:06 24 4
gpt4 key购买 nike

我写了一个很好的优先级队列类,

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

我现在想将其包装在 BlockingCollection 中,

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

这样它可以增加最大容量,并希望有一些线程安全。然而,现在我似乎失去了可观察的功能!

我怎样才能将 DataGrid 连接到这个集合,以便它仍能收到集合更改通知?

最佳答案

绑定(bind)到底层集合(优先级队列)似乎有效。然后,我只调用阻塞集合上的 AddTake。我想这就是他们决定将对象分开的原因。

关于c# - 如何使 BlockingCollection 可观察?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3966629/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com