Example #1
0
        private void Dispatch(MessageDispatch dispatch, IMessageHandlerInvoker invoker)
        {
            var context    = dispatch.Context.WithDispatchQueueName(invoker.DispatchQueueName);
            var invocation = _pipeManager.BuildPipeInvocation(invoker, dispatch.Message, context);

            var isInSameDispatchQueue = ShouldRunInCurrentDispatchQueue(invoker.DispatchQueueName, dispatch.Context.DispatchQueueName);

            if (invoker.CanInvokeSynchronously && (dispatch.ShouldRunSynchronously || isInSameDispatchQueue))
            {
                DispatchSync(invocation, dispatch);
            }
            else
            {
                DispatchAsync(invocation, dispatch);
            }
        }
Example #2
0
        private void RunBatch(Batch batch)
        {
            if (batch.IsEmpty)
            {
                return;
            }

            try
            {
                if (!_isRunning)
                {
                    return;
                }

                switch (batch.FirstEntry.Invoker !.Mode)
                {
                case MessageHandlerInvokerMode.Synchronous:
                {
                    SynchronizationContext.SetSynchronizationContext(null);
                    var invocation = _pipeManager.BuildPipeInvocation(batch.FirstEntry.Invoker, batch.Messages, batch.FirstEntry.Dispatch !.Context);
                    invocation.Run();
                    batch.SetHandled(null);
                    break;
                }