Advertisement
Guest User

WPF IContext

a guest
Jul 10th, 2011
2,787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. public sealed class WpfContext
  2.     : IContext
  3. {
  4.     private readonly Dispatcher _dispatcher;
  5.  
  6.     public bool IsSynchronized
  7.     {
  8.         get
  9.         {
  10.             return this._dispatcher.Thread == Thread.CurrentThread;
  11.         }
  12.     }
  13.  
  14.     public WpfContext()
  15.         : this(Dispatcher.CurrentDispatcher)
  16.     {
  17.     }
  18.     public WpfContext(Dispatcher dispatcher)
  19.     {
  20.         Debug.Assert(dispatcher != null);
  21.  
  22.         this._dispatcher = dispatcher;
  23.     }
  24.  
  25.     public void Invoke(Action action)
  26.     {
  27.         Debug.Assert(action != null);
  28.  
  29.         this._dispatcher.Invoke(action);
  30.     }
  31.     public void BeginInvoke(Action action)
  32.     {
  33.         Debug.Assert(action != null);
  34.  
  35.         this._dispatcher.BeginInvoke(action);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement