Ejemplo n.º 1
0
        /// <summary>
        /// Looks for a new message to process
        /// </summary>
        public void Handle()
        {
            try
            {
                try
                {
                    TryProcessIncomingMessage();
                }
                catch (MessageException exception)
                {
                    UserException?.Invoke(this, new MessageErrorEventArgs(exception));
                }
                catch (CommitException exception)
                {
                    UserException?.Invoke(this, new MessageErrorEventArgs(exception));
                }
                catch (Exception e)
                {
                    SystemException?.Invoke(this, new MessageErrorEventArgs(e));

                    //generic exceptions tend to indicate a serious problem - lets start delaying processing
                    //this counter will reset once a message has been processed by this thread
                    _seriousExceptionProcessBackOffHelper.Value.Wait();
                }
            }
            catch (Exception ex) //not cool - one of the exception events threw an exception
            {
                //there isn't a whole lot we can do here
                _log.ErrorException("An error has occurred while trying to handle an exception", ex, null);
            }
        }
        /// <summary>
        /// Looks for and processes a new message
        /// </summary>
        public async void Handle()
        {
            Interlocked.Increment(ref _waitingOnAsyncTasks);
            try
            {
                try
                {
                    await TryProcessIncomingMessageAsync().ConfigureAwait(false);

                    _seriousExceptionProcessBackOffHelper.Value.Reset();
                }
                catch (MessageException exception)
                {
                    UserException?.Invoke(this, new MessageErrorEventArgs(exception));
                }
                catch (CommitException exception)
                {
                    UserException?.Invoke(this, new MessageErrorEventArgs(exception));
                }
                catch (Exception e)
                {
                    SystemException?.Invoke(this, new MessageErrorEventArgs(e));

                    //generic exceptions tend to indicate a serious problem - lets start delaying processing
                    //this counter will reset once a message has been processed by this thread
                    _seriousExceptionProcessBackOffHelper.Value.Wait();
                }
            }
            catch (Exception ex) //not cool - one of the exception events threw an exception
            {
                //there is not a lot we can do here - log the exception
                _log.ErrorException("An error has occurred while trying to handle an exception", ex, null);
            }
            finally
            {
                Interlocked.Decrement(ref _waitingOnAsyncTasks);
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Raises the system exception.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The <see cref="WorkerErrorEventArgs"/> instance containing the event data.</param>
 protected void RaiseSystemException(object sender, WorkerErrorEventArgs e)
 {
     SystemException?.Invoke(sender, e);
 }