Advertisement
Guest User

ObservableCollection Dispatcher stuffs

a guest
Sep 26th, 2011
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. protected override void OnCollectionChanged ( System.Collections.Specialized.NotifyCollectionChangedEventArgs e )
  2. {
  3.     var dlgCollectionChangedDispatcher = CollectionChangedDispatcher;
  4.     if ( dlgCollectionChangedDispatcher != null )
  5.         Runner.RunOnDispatcherThreadSync ( ( ) => dlgCollectionChangedDispatcher ( this, e ) );
  6.  
  7.     var dlgCollectionChangedNormal = CollectionChangedNormal;
  8.     if ( dlgCollectionChangedNormal != null )
  9.         dlgCollectionChangedNormal ( this, e );
  10. }
  11.        
  12. private event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChangedNormal;
  13. private event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChangedDispatcher;
  14.  
  15. public override event System.Collections.Specialized.NotifyCollectionChangedEventHandler CollectionChanged
  16. {
  17.     add
  18.     {
  19.         if ( Dispatcher.Thread == System.Threading.Thread.CurrentThread )
  20.             CollectionChangedDispatcher += value;
  21.         else
  22.             CollectionChangedNormal += value;
  23.     }
  24.     remove
  25.     {
  26.         if ( Dispatcher.Thread == System.Threading.Thread.CurrentThread )
  27.             CollectionChangedDispatcher -= value;
  28.         else
  29.             CollectionChangedNormal -= value;
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement