2011-09-22 93 views
5

有沒有辦法從BlockingCollection刪除特定項目,像這樣:從BlockingCollection <>刪除特定項目

IMyItem mySpecificItem = controller.getTopRequestedItem(); 
bool took = myBlockingCollection<IMyItem>.TryTake(out mySpecificItem); 
if(took) 
    process(mySpecificItem); 
..... 
換句話說

:我想從一個BlockingCollection刪除項目<>,它由一些字段(例如ID)標識,而不僅僅是下一個可用項目。

我需要實現getHashCode()還是IComparer?

回答

7

BlockingCollection<>不會幫你在這裏。我認爲你需要ConcurrentDictionary<>

+0

沒有辦法通過IComparer或HashCode? –

+1

這會有幫助嗎? 'BlockingCollection <>'沒有任何方法允許特定元素被拉出。 –

+0

感謝您的澄清。 ConcurrentDictionary <>的問題是沒有順序。在我的場景中,我需要一個物品管道,能夠不時從管道中間刪除優先項目。剩下的時間項目應該被處理FirstInFirstOut。當我有解決方案時,我會回到這個線程。 –