@@ -13,7 +13,9 @@ internal sealed class ProcessTerminationHandler : IDisposable
1313 private readonly CancellationTokenSource _handlerCancellationTokenSource ;
1414 private readonly Task < int > _startedHandler ;
1515 private readonly TimeSpan _processTerminationTimeout ;
16+ #if NET7_0_OR_GREATER
1617 private readonly IDisposable ? _sigIntRegistration , _sigTermRegistration ;
18+ #endif
1719
1820 internal ProcessTerminationHandler (
1921 CancellationTokenSource handlerCancellationTokenSource ,
@@ -25,7 +27,7 @@ internal ProcessTerminationHandler(
2527 _startedHandler = startedHandler ;
2628 _processTerminationTimeout = processTerminationTimeout ;
2729
28- #if NET7_0_OR_GREATER
30+ #if NET7_0_OR_GREATER // we prefer the new API as they allow for cancelling SIGTERM
2931 if ( ! OperatingSystem . IsAndroid ( )
3032 && ! OperatingSystem . IsIOS ( )
3133 && ! OperatingSystem . IsTvOS ( )
@@ -43,16 +45,17 @@ internal ProcessTerminationHandler(
4345
4446 public void Dispose ( )
4547 {
48+ #if NET7_0_OR_GREATER
4649 if ( _sigIntRegistration is not null )
4750 {
4851 _sigIntRegistration . Dispose ( ) ;
4952 _sigTermRegistration ! . Dispose ( ) ;
53+ return ;
5054 }
51- else
52- {
53- Console . CancelKeyPress -= OnCancelKeyPress ;
54- AppDomain . CurrentDomain . ProcessExit -= OnProcessExit ;
55- }
55+ #endif
56+
57+ Console . CancelKeyPress -= OnCancelKeyPress ;
58+ AppDomain . CurrentDomain . ProcessExit -= OnProcessExit ;
5659 }
5760
5861#if NET7_0_OR_GREATER
0 commit comments