Skip to content

Commit 3c2a490

Browse files
committed
fix: don't cancel the ctrl+c event
Fixes #302
1 parent 7cee170 commit 3c2a490

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
[See unreleased changes][unreleased].
44

5+
## [v2.4.4](https://github.com/natemcmaster/CommandLineUtils/compare/v2.4.3...v2.4.4)
6+
7+
* Fix [#302] - fix regression introduced in 2.4.2 which caused Ctrl+C handling not to terminate the process quickly
8+
9+
[#302]: https://github.com/natemcmaster/CommandLineUtils/issues/302
10+
511
## [v2.4.3](https://github.com/natemcmaster/CommandLineUtils/compare/v2.4.2...v2.4.3)
612

713
* Fix [#292] by [@thomaslevesque] - fix deadlock when `Environment.Exit` is called

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
</PropertyGroup>
3535

3636
<PropertyGroup>
37-
<VersionPrefix>2.4.3</VersionPrefix>
37+
<VersionPrefix>2.4.4</VersionPrefix>
3838
<VersionSuffix>build</VersionSuffix>
3939
<IncludePreReleaseLabelInPackageVersion Condition="'$(IsStableBuild)' != 'true'">true</IncludePreReleaseLabelInPackageVersion>
4040
<BuildNumber Condition=" '$(BuildNumber)' == '' ">$(BUILD_NUMBER)</BuildNumber>

src/CommandLineUtils/CommandLineApplication.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -876,19 +876,15 @@ public async Task<int> ExecuteAsync(string[] args, CancellationToken cancellatio
876876
return command.ValidationErrorHandler(validationResult);
877877
}
878878

879-
var handlerCompleted = new ManualResetEventSlim(initialState: false);
880879
var handlerCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
881880

882881
void cancelHandler(object o, ConsoleCancelEventArgs e)
883882
{
884883
handlerCancellationTokenSource.Cancel();
885-
// Stops the process from exiting forcefully
886-
e.Cancel = true;
887884
}
888885

889886
try
890887
{
891-
// blocks .NET's CTRL+C handler from completing until after async completions are done
892888
_context.Console.CancelKeyPress += cancelHandler;
893889

894890
return await command._handler(handlerCancellationTokenSource.Token);
@@ -900,7 +896,6 @@ void cancelHandler(object o, ConsoleCancelEventArgs e)
900896
finally
901897
{
902898
_context.Console.CancelKeyPress -= cancelHandler;
903-
handlerCompleted.Set();
904899
}
905900
}
906901

src/CommandLineUtils/releasenotes.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ Other things I fixed:
1616
* Add async methods that accept cancellation tokens
1717
* Handle CTRL+C by default
1818
* Support calling CommandLineApplication.Execute multiple times
19+
</PackageReleaseNotes>
20+
<PackageReleaseNotes Condition="'$(VersionPrefix)' == '2.4.4'">
21+
$(PackageReleaseNotes)
22+
23+
2.4.4 patch:
24+
* Fix regression introduced in 2.4.2 which caused Ctrl+C handling not to terminate the process quickly
1925
</PackageReleaseNotes>
2026
<PackageReleaseNotes Condition="'$(VersionPrefix)' == '2.4.3'">
2127
$(PackageReleaseNotes)

0 commit comments

Comments
 (0)