public override void OnInvoke(MethodInterceptionArgs args) { IDispatcherObject threadAffined = args.Instance as IDispatcherObject; IDispatcher dispatcher = threadAffined.Dispatcher; if (dispatcher == null) { throw new InvalidOperationException("Cannot dispatch method: synchronization context is null"); } if (this.isAsync) { dispatcher.BeginInvoke(new WorkItem(args, true)); } else if (dispatcher.CheckAccess()) { args.Proceed(); } else { WorkItemWithExceptionInterceptor workItem = new WorkItemWithExceptionInterceptor(args); dispatcher.Invoke(workItem); if (workItem.HasError) { throw new AggregateException("Exception has been thrown by the target of an invocation", workItem.Exception); } } }
public override void OnInvoke( MethodInterceptionArgs args ) { IDispatcherObject threadAffined = args.Instance as IDispatcherObject; IDispatcher dispatcher = threadAffined.Dispatcher; if ( dispatcher == null ) { throw new InvalidOperationException( "Cannot dispatch method: synchronization context is null" ); } if ( this.isAsync ) { dispatcher.BeginInvoke( new WorkItem( args, true ) ); } else if ( dispatcher.CheckAccess() ) { args.Proceed(); } else { WorkItemWithExceptionInterceptor workItem = new WorkItemWithExceptionInterceptor(args); dispatcher.Invoke(workItem); if (workItem.HasError) { throw new AggregateException( "Exception has been thrown by the target of an invocation", workItem.Exception ); } } }