Ejemplo n.º 1
0
            public bool ProcessSyncCallback(LocalLogMessage message, out bool queueForAsyncProcessing)
            {
                queueForAsyncProcessing = ProcessSyncCallbackQueueForAsyncProcessing;

                ProcessSyncCallbackWasCalled = true;
                MessagePassedToProcessSyncCallback?.Release();
                MessagePassedToProcessSyncCallback = message;
                MessagePassedToProcessSyncCallback.AddRef();

                return(ProcessSyncCallbackReturnValue);
            }
        /// <summary>
        /// Is called on behalf of <see cref="ProcessingPipelineStage.ProcessMessage"/> (for internal use only).
        /// This method must not throw exceptions.
        /// </summary>
        /// <param name="message">Message to process.</param>
        /// <returns>
        /// true to pass the message to the following stages;
        /// false to stop processing the message.
        /// </returns>
        internal override bool OnProcessMessageBase(LocalLogMessage message)
        {
            try
            {
                // synchronous processing
                bool proceed = ProcessSync(message, out bool queueMessageForAsynchronousProcessing);

                // asynchronous processing
                if (queueMessageForAsynchronousProcessing)
                {
                    if (mDiscardMessagesIfQueueFull)
                    {
                        message.AddRef();
                        bool pushed = mAsyncProcessingMessageStack.TryPush(message);
                        if (pushed)
                        {
                            mTriggerAsyncProcessingEvent.Set();
                        }
                        else
                        {
                            message.Release();
                        }
                    }
                    else
                    {
                        message.AddRef();
                        while (!mAsyncProcessingMessageStack.TryPush(message))
                        {
                            Thread.Sleep(10);
                        }
                        mTriggerAsyncProcessingEvent.Set();
                    }
                }

                return(proceed);
            }
            catch (Exception ex)
            {
                // swallow exception to avoid crashing the application, if the exception is not handled properly
                Debug.Fail("The pipeline stage threw an exception processing the message.", ex.ToString());

                // let the following stages process the message
                // (hopefully this is the right decision in this case)
                return(true);
            }
        }