Archive

GUI Dispatch

Custom Attribute That Dispatches the Method to the GUI Thread

public class GuiThreadAttribute : OnMethodInvocationAspect
{
  public override void OnInvocation(MethodInvocationEventArgs eventArgs)
  {
    DispatcherObject dispatcherObject = (DispatcherObject)eventArgs.Delegate.Target;

    if (dispatcherObject.CheckAccess())
      eventArgs.Proceed();
    else
      dispatcherObject.Dispatcher.Invoke( DispatcherPriority.Normal,
                                          new
Action(() => eventArgs.Proceed()));
  }
}

Comments are closed