Esempio n. 1
0
        public IAsyncResult BeginInvoke(string topic, object source, object e, AsyncCallback callback, object callbackState)
        {
            if (topic == null)
            {
                throw new ArgumentNullException("topic");
            }
            ExTraceGlobals.DispatchTracer.TraceDebug <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "async dispatch event {0} {1} callback", topic, (callback == null) ? "without" : "with");
            if (this.closed)
            {
                throw new InvalidOperationException(MExRuntimeStrings.InvalidState);
            }
            MExAsyncResult result = new MExAsyncResult(callback, callbackState);

            if (!this.dispatcher.HasHandler(topic))
            {
                ExTraceGlobals.DispatchTracer.TraceDebug <string>((long)this.GetHashCode(), this.InstanceNameFormatted + "no handler for {0}", topic);
                this.pendingResult = result;
                this.pendingResult.InvokeCompleted();
            }
            else
            {
                lock (this.syncRoot)
                {
                    if (this.closed)
                    {
                        throw new InvalidOperationException(MExRuntimeStrings.InvalidState);
                    }
                    this.BindContexts(source, e);
                    this.eventTopic    = topic;
                    this.pendingResult = result;
                    this.AsyncInvoke(null);
                }
            }
            return(result);
        }
Esempio n. 2
0
 private void AgentAsyncCompletionCallback(AgentAsyncContext context)
 {
     if (this.resumeAgentCallback != null && this.resumeAgentCallback())
     {
         MExDiagnostics.EventLog.LogEvent(EdgeExtensibilityEventLogConstants.Tuple_MExAgentDidNotCallResume, this.lastAgentName, new object[]
         {
             this.lastAgentName,
             this.eventTopic
         });
     }
     ExTraceGlobals.DispatchTracer.TraceDebug <string, string>((long)this.GetHashCode(), this.InstanceNameFormatted + "async completed, async result {0}, exception {1}", this.isSyncInvoke ? "n/a" : this.pendingResult.GetHashCode().ToString(CultureInfo.InvariantCulture), (context.AsyncException == null) ? "n/a" : context.AsyncException.GetType().FullName);
     if (this.isSyncInvoke)
     {
         if (context.AsyncException != null)
         {
             MExAsyncResult.WrapAndRethrowException(context.AsyncException, new LocalizedString(MExRuntimeStrings.AgentFault(this.currentAgent.Name, this.eventTopic)));
         }
         this.syncWaitHandle.Set();
         return;
     }
     if (context.AsyncException != null)
     {
         this.pendingResult.AsyncException = context.AsyncException;
         this.HaltExecution();
         MExSession.LogMexAgentFaultEvent(MExDiagnostics.EventLog, context.AsyncException, this.currentAgent.Name, this.eventTopic);
     }
     if (this.completeAsyncAgentCallback != null)
     {
         this.completeAsyncAgentCallback();
     }
     this.Dispatcher.AgentInvokeCompleted(this);
     this.ResumeExecution();
 }
Esempio n. 3
0
        internal void EndInvoke()
        {
            if (this.asyncException != null)
            {
                MExAsyncResult.WrapAndRethrowException(this.asyncException, new LocalizedString(MExRuntimeStrings.AgentFault(this.faultyAgentName, this.eventTopic)));
            }
            WaitHandle waitHandle = null;

            lock (this.syncRoot)
            {
                if (!this.isCompleted)
                {
                    waitHandle = this.AsyncWaitHandle;
                }
            }
            if (waitHandle != null)
            {
                waitHandle.WaitOne();
            }
            if (this.asyncException != null)
            {
                MExAsyncResult.WrapAndRethrowException(this.asyncException, new LocalizedString(MExRuntimeStrings.AgentFault(this.faultyAgentName, this.eventTopic)));
            }
        }