Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ec6343f

Browse files
committed
Merge pull request #2418 from stephentoub/process_waittimeout_unix
Fix Process.WaitForExit premature timeout on Unix
2 parents 50ad57b + 3f79c35 commit ec6343f

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/System.Diagnostics.Process/src/System/Diagnostics/ProcessWaitState.Unix.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ internal bool WaitForExit(int millisecondsTimeout)
367367
Debug.Assert(!Monitor.IsEntered(_gate));
368368

369369
// Track the time the we start waiting.
370-
long startTime = GetTimestamp();
370+
long startTime = Stopwatch.GetTimestamp();
371371

372372
// Polling loop
373373
while (true)
@@ -379,7 +379,7 @@ internal bool WaitForExit(int millisecondsTimeout)
379379
// We're in a polling loop... determine how much time remains
380380
int remainingTimeout = millisecondsTimeout == Timeout.Infinite ?
381381
Timeout.Infinite :
382-
(int)Math.Max(millisecondsTimeout - (GetTimestamp() - startTime), 0);
382+
(int)Math.Max(millisecondsTimeout - ((Stopwatch.GetTimestamp() - startTime) / (double)Stopwatch.Frequency * 1000), 0);
383383

384384
lock (_gate)
385385
{
@@ -511,11 +511,5 @@ internal bool WaitForExit(int millisecondsTimeout)
511511
});
512512
}
513513

514-
/// <summary>Gets a current time stamp.</summary>
515-
private static long GetTimestamp()
516-
{
517-
return Stopwatch.GetTimestamp();
518-
}
519-
520514
}
521515
}

0 commit comments

Comments
 (0)