SHARE
TWEET

WPF IContext

a guest Jul 10th, 2011 2,530 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top