문제

inotifyCollectionChanged를 구현하는 .NET의 일반 큐 버전을 작성한 사람이 있습니까?

도움이 되었습니까?

해결책

빠른 검색에는 결과가 표시되지 않았습니다. 그러나 인터페이스는 간단하며 큐 클래스를 확장하고 인터페이스에 대한 지원을 추가하는 것은 거의 사소합니다. 따라서 모든 방법을 무시합니다.

// this isn't the best code ever; refactor as desired
protected void OnCollectionChanged( NotifyCollectionChangedEventArgs ccea){
  var temp = CollectionChanged;
  if(temp != null) temp(this, ccea);  
}

// and later in the class

public override SomeMethodThatAltersTheQueue(object something){
  // record state of collection prior to change
  base.SomeMethodThatAltersTheQueue(something)
  // create NotifyCollectionChangedEventArgs with prior state and new state
  OnCollectionChanged(ccea);
}

다른 팁

나는 Chris Wenham과 같은 접근법을 사용했습니다. 부하 하에서, 새로운 notifyCollectionChangeDeventArgs는 각 enqueue/dequeue에 대해 할당되어야하기 때문에 성능이 어려워집니다.

그럼에도 불구하고, Enqueue에서는 NotifyCollectionChangedAction.Add를 사용하여 Args를 보냅니다. 항목은 추가 및 Count-1을 색인으로 보냅니다. Dequeue에서는 notifyCollectionChangedAction.Remove를 사용하여 Args를 보내고 제거 된 항목 및 색인 0.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top