77
88namespace ProcNet
99{
10+ public class LongRunningApplicationSubscription : IDisposable
11+ {
12+ internal LongRunningApplicationSubscription ( ObservableProcess process , CompositeDisposable subscription )
13+ {
14+ Process = process ;
15+ Subscription = subscription ;
16+ }
17+
18+ private IDisposable Subscription { get ; }
19+
20+ public ObservableProcess Process { get ; }
21+
22+ public bool SendControlC ( int processId ) => Process . SendControlC ( processId ) ;
23+ public void SendControlC ( ) => Process . SendControlC ( ) ;
24+
25+ public void Dispose ( )
26+ {
27+ Subscription ? . Dispose ( ) ;
28+ Process ? . Dispose ( ) ;
29+ }
30+ }
31+
1032 public static partial class Proc
1133 {
1234
@@ -28,7 +50,7 @@ public static partial class Proc
2850 /// <para>defaults to <see cref="ConsoleOutColorWriter"/> which writes standard error messages in red</para>
2951 /// </param>
3052 /// <returns>The exit code and whether the process completed</returns>
31- public static IDisposable StartLongRunning ( LongRunningArguments arguments , TimeSpan waitForStartedConfirmation , IConsoleOutWriter consoleOutWriter = null )
53+ public static LongRunningApplicationSubscription StartLongRunning ( LongRunningArguments arguments , TimeSpan waitForStartedConfirmation , IConsoleOutWriter consoleOutWriter = null )
3254 {
3355 var started = false ;
3456 var confirmWaitHandle = new ManualResetEvent ( false ) ;
@@ -71,7 +93,7 @@ public static IDisposable StartLongRunning(LongRunningArguments arguments, TimeS
7193 else
7294 {
7395 var completed = confirmWaitHandle . WaitOne ( waitForStartedConfirmation ) ;
74- if ( completed ) return composite ;
96+ if ( completed ) return new ( process , composite ) ;
7597 var pwd = arguments . WorkingDirectory ;
7698 var args = arguments . Args . NaivelyQuoteArguments ( ) ;
7799 var printBinary = arguments . OnlyPrintBinaryInExceptionMessage
@@ -80,7 +102,7 @@ public static IDisposable StartLongRunning(LongRunningArguments arguments, TimeS
80102 throw new ProcExecException ( $ "Could not yield started confirmation after { waitForStartedConfirmation } while running { printBinary } ") ;
81103 }
82104
83- return composite ;
105+ return new ( process , composite ) ;
84106 }
85107 }
86108}
0 commit comments