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."); } }
public DispatcherWrapper(object dispatcher) { this.dispatcher = dispatcher; WpfDispatcherBinding.BeginInvoke( dispatcher, (int)Enum.Parse(dispatcherPriorityType, "Send"), () => this.synchronizationContext = SynchronizationContext.Current); }
public void BeginInvoke(IAction action) { WpfDispatcherBinding.BeginInvoke(this.dispatcher, (int)Enum.Parse(dispatcherPriorityType, "Send"), action.Invoke); }
public void Invoke(IAction action) { WpfDispatcherBinding.Invoke(this.dispatcher, action.Invoke); }
public bool CheckAccess() { return(WpfDispatcherBinding.CheckAccess(this.dispatcher)); }