33
44
55using System . Diagnostics ;
6+ using Microsoft . DotNet . Cli . Utils ;
67
78namespace Microsoft . DotNet . Watch
89{
@@ -84,7 +85,7 @@ public async Task<int> RunAsync(ProcessSpec processSpec, IReporter reporter, boo
8485 {
8586 try
8687 {
87- _ = await WaitForExitAsync ( process , timeout : null , processTerminationToken ) ;
88+ _ = await WaitForExitAsync ( process , timeout : null , reporter : null , processTerminationToken ) ;
8889 }
8990 catch ( OperationCanceledException )
9091 {
@@ -221,7 +222,7 @@ private async ValueTask TerminateProcessAsync(Process process, ProcessState stat
221222 // Ctrl+C hasn't been sent, force termination.
222223 // We don't have means to terminate gracefully on Windows (https://github.com/dotnet/runtime/issues/109432)
223224 TerminateProcess ( process , state , reporter , force : true ) ;
224- _ = await WaitForExitAsync ( process , timeout : null , cancellationToken ) ;
225+ _ = await WaitForExitAsync ( process , state , timeout : null , reporter , cancellationToken ) ;
225226
226227 return ;
227228 }
@@ -233,30 +234,39 @@ private async ValueTask TerminateProcessAsync(Process process, ProcessState stat
233234 }
234235
235236 // Ctlr+C/SIGTERM has been sent, wait for the process to exit gracefully.
236- if ( ! await WaitForExitAsync ( process , processCleanupTimeout , cancellationToken ) )
237+ if ( ! await WaitForExitAsync ( process , state , processCleanupTimeout , reporter , cancellationToken ) )
237238 {
238239 // Force termination if the process is still running after the timeout.
239240 TerminateProcess ( process , state , reporter , force : true ) ;
240241
241- _ = await WaitForExitAsync ( process , timeout : null , cancellationToken ) ;
242+ _ = await WaitForExitAsync ( process , state , timeout : null , reporter , cancellationToken ) ;
242243 }
243244 }
244245
245- private static async ValueTask < bool > WaitForExitAsync ( Process process , TimeSpan ? timeout , CancellationToken cancellationToken )
246+ private static async ValueTask < bool > WaitForExitAsync ( Process process , ProcessState state , TimeSpan ? timeout , IReporter ? reporter , CancellationToken cancellationToken )
246247 {
247248 var task = process . WaitForExitAsync ( cancellationToken ) ;
248249
249250 if ( timeout . HasValue )
250251 {
251252 try
252253 {
254+ reporter ? . Verbose ( $ "Waiting for process { state . ProcessId } to exit within { timeout . Value . TotalSeconds } s.") ;
253255 await task . WaitAsync ( timeout . Value , cancellationToken ) ;
254256 }
255257 catch ( TimeoutException )
256258 {
257259 return false ;
258260 }
259261 }
262+ else if ( reporter ? . IsVerbose == true )
263+ {
264+ int i = 0 ;
265+ while ( Task . WaitAny ( [ task , Task . Delay ( TimeSpan . FromSeconds ( 5 ) , cancellationToken ) ] , cancellationToken ) != 0 )
266+ {
267+ reporter . Verbose ( $ "Waiting for process { state . ProcessId } to exit ({ i ++ } ).") ;
268+ }
269+ }
260270 else
261271 {
262272 await task ;
@@ -265,6 +275,7 @@ private static async ValueTask<bool> WaitForExitAsync(Process process, TimeSpan?
265275 // ensures that all process output has been reported:
266276 try
267277 {
278+ reporter ? . Verbose ( $ "Waiting for output of process { state . ProcessId } to complete.") ;
268279 process . WaitForExit ( ) ;
269280 }
270281 catch
0 commit comments