Skip to content

Commit

Permalink
fix: don't dispose ManualResetEvent which might be used later
Browse files Browse the repository at this point in the history
Fixes #261
  • Loading branch information
natemcmaster committed Aug 13, 2019
1 parent a89c61f commit 38a5c76
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/Hosting.CommandLine/Internal/CommandLineLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// Creates a new instance.
Expand Down Expand Up @@ -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.
Expand All @@ -100,8 +100,7 @@ public Task WaitForStartAsync(CancellationToken cancellationToken)

public void Dispose()
{
_disposeComplete.Set();
_disposeComplete.Dispose();
_blockProcessExit.Set();
}
}
}

0 comments on commit 38a5c76

Please sign in to comment.