ObservableQueue?

前端 未结 2 933
借酒劲吻你
借酒劲吻你 2021-01-28 07:25

Has anyone written a version of .Net\'s generic Queue that implements INotifyCollectionChanged, or is there one hidden deep in the .Net framework somewhere already?

2条回答
  •  误落风尘
    2021-01-28 07:54

    I used the same approach as Chris Wenham. Under load, performance suffers because new NotifyCollectionChangedEventArgs need to be allocated for each Enqueue/Dequeue.

    Regardless, in the Enqueue, send args with NotifyCollectionChangedAction.Add, the item added, and Count-1 as the index. In the Dequeue, send args with NotifyCollectionChangedAction.Remove, the item removed, and index 0.

提交回复
热议问题