コード例 #1
0
ファイル: ThreadPoolWorker.cs プロジェクト: rebus-org/Rebus
        async void TryAsyncReceive(CancellationToken token, IDisposable parallelOperation)
        {
            try
            {
                using (parallelOperation)
                using (var context = new TransactionContext())
                {
                    var transportMessage = await ReceiveTransportMessage(token, context);

                    if (transportMessage == null)
                    {
                        context.Dispose();

                        // no need for another thread to rush in and discover that there is no message
                        //parallelOperation.Dispose();

                        _backoffStrategy.WaitNoMessage();
                        return;
                    }

                    _backoffStrategy.Reset();

                    await ProcessMessage(context, transportMessage);
                }
            }
            catch (TaskCanceledException)
            {
                // it's fine - just a sign that we are shutting down
            }
            catch (OperationCanceledException)
            {
                // it's fine - just a sign that we are shutting down
            }
            catch (Exception exception)
            {
                _log.Error(exception, "Unhandled exception in thread pool worker");
            }
        }