public void RuntimeInitializeInstance()
            {
                SynchronizationContext synchronizationContext = SynchronizationContext.Current;

                if (synchronizationContext != null)
                {
                    this.dispatcher = new SynchronizationContextWrapper(synchronizationContext);
                }
                else
                {
                    //Sometimes there's still no SynchronizationContext, even though Dispatcher is already available
                    IDispatcher dispatcher = WpfDispatcherBinding.TryFindWpfDispatcher(Thread.CurrentThread);

                    if (dispatcher != null)
                    {
                        this.dispatcher = dispatcher;
                    }
                }

                if (this.dispatcher == null)
                {
                    throw new InvalidOperationException(
                              "Instances of classes marked with DispatcherObjectAspect can only be crated on threads with synchronization contexts " +
                              "(typically WPF or Windows.Forms UI threads), or must implement IDispatcherObject manually.");
                }
            }
Exemplo n.º 2
0
            public DispatcherWrapper(object dispatcher)
            {
                this.dispatcher = dispatcher;

                WpfDispatcherBinding.BeginInvoke(
                    dispatcher, (int)Enum.Parse(dispatcherPriorityType, "Send"), () => this.synchronizationContext = SynchronizationContext.Current);
            }
Exemplo n.º 3
0
 public void BeginInvoke(IAction action)
 {
     WpfDispatcherBinding.BeginInvoke(this.dispatcher, (int)Enum.Parse(dispatcherPriorityType, "Send"), action.Invoke);
 }
Exemplo n.º 4
0
 public void Invoke(IAction action)
 {
     WpfDispatcherBinding.Invoke(this.dispatcher, action.Invoke);
 }
Exemplo n.º 5
0
 public bool CheckAccess()
 {
     return(WpfDispatcherBinding.CheckAccess(this.dispatcher));
 }