From 38a5c7675ef4b629237786993fa35ad7daaaae74 Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Mon, 12 Aug 2019 20:30:33 -0700 Subject: [PATCH] fix: don't dispose ManualResetEvent which might be used later Fixes #261 --- src/Hosting.CommandLine/Internal/CommandLineLifetime.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Hosting.CommandLine/Internal/CommandLineLifetime.cs b/src/Hosting.CommandLine/Internal/CommandLineLifetime.cs index 5df0d491..930a95dc 100644 --- a/src/Hosting.CommandLine/Internal/CommandLineLifetime.cs +++ b/src/Hosting.CommandLine/Internal/CommandLineLifetime.cs @@ -20,7 +20,7 @@ internal class CommandLineLifetime : IHostLifetime, IDisposable private readonly ICommandLineService _cliService; private readonly IConsole _console; private readonly IUnhandledExceptionHandler? _unhandledExceptionHandler; - private readonly ManualResetEvent _disposeComplete = new ManualResetEvent(false); + private readonly ManualResetEvent _blockProcessExit = new ManualResetEvent(false); /// /// Creates a new instance. @@ -81,11 +81,11 @@ public Task WaitForStartAsync(CancellationToken cancellationToken) } }); - // Ensures services are disposed before the application exits. AppDomain.CurrentDomain.ProcessExit += (_, __) => { _applicationLifetime.StopApplication(); - _disposeComplete.WaitOne(); + // Ensures services are disposed before the application exits. + _blockProcessExit.WaitOne(); }; // Capture CTRL+C and prevent it from immediately force killing the app. @@ -100,8 +100,7 @@ public Task WaitForStartAsync(CancellationToken cancellationToken) public void Dispose() { - _disposeComplete.Set(); - _disposeComplete.Dispose(); + _blockProcessExit.Set(); } } }