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()));
  }
}

Trace

Custom Attribute That Traces

public class TraceAttribute : OnMethodBoundaryAspect 
{ 
  public override void OnEntry( MethodExecutionEventArgs eventArgs) 
  { Trace.TraceInformation("Entering {0}.", eventArgs.Method);  } 

  public override void OnExit( MethodExecutionEventArgs eventArgs) 
  { Trace.TraceInformation("Leaving {0}.", eventArgs.Method);   } 
}

Video

See PostSharp

{loadposition inset}

Please note that this video is already 2 years old so it is not completely accurate any more.
Try Firefox or Chrome if this video does not play with Internet Explorer.