From cd3a595ea63972b189ff517f22f98207e43c782b Mon Sep 17 00:00:00 2001 From: Savorboard Date: Wed, 9 May 2018 20:59:07 +0800 Subject: [PATCH] Fixed exception thrown when terminate the program with Ctrl+C. (#130) --- CAP.sln | 1 + .../Processor/IProcessingServer.Cap.cs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CAP.sln b/CAP.sln index 952416d..828d82a 100644 --- a/CAP.sln +++ b/CAP.sln @@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution CHANGELOG.md = CHANGELOG.md CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md ConfigureMSDTC.ps1 = ConfigureMSDTC.ps1 + .github\ISSUE_TEMPLATE = .github\ISSUE_TEMPLATE LICENSE.txt = LICENSE.txt README.md = README.md README.zh-cn.md = README.zh-cn.md diff --git a/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs b/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs index b9d8802..551556e 100644 --- a/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs +++ b/src/DotNetCore.CAP/Processor/IProcessingServer.Cap.cs @@ -57,13 +57,14 @@ namespace DotNetCore.CAP.Processor return; } - _disposed = true; - - _logger.ServerShuttingDown(); - _cts.Cancel(); try { - _compositeTask.Wait((int) TimeSpan.FromSeconds(10).TotalMilliseconds); + _disposed = true; + + _logger.ServerShuttingDown(); + _cts.Cancel(); + + _compositeTask?.Wait((int)TimeSpan.FromSeconds(10).TotalMilliseconds); } catch (AggregateException ex) { @@ -73,6 +74,10 @@ namespace DotNetCore.CAP.Processor _logger.ExpectedOperationCanceledException(innerEx); } } + catch (Exception ex) + { + _logger.LogWarning(ex, "An exception was occured when disposing..."); + } } private IProcessor InfiniteRetry(IProcessor inner)