@@ -133,11 +133,13 @@ public void TestExitTime()
133
133
{
134
134
DateTime timeBeforeProcessStart = DateTime . UtcNow ;
135
135
Process p = CreateProcessInfinite ( ) ;
136
- StartAndKillProcessWithDelay ( p ) ;
136
+ p . Start ( ) ;
137
+ Assert . Throws < InvalidOperationException > ( ( ) => p . ExitTime ) ;
138
+ p . Kill ( ) ;
139
+ Assert . True ( p . WaitForExit ( WaitInMS ) ) ;
137
140
Assert . True ( p . ExitTime . ToUniversalTime ( ) > timeBeforeProcessStart , "TestExitTime is incorrect." ) ;
138
141
}
139
142
140
-
141
143
[ Fact ]
142
144
public void TestId ( )
143
145
{
@@ -366,6 +368,8 @@ public void TestProcessStartTime()
366
368
{
367
369
DateTime timeBeforeCreatingProcess = DateTime . UtcNow ;
368
370
Process p = CreateProcessInfinite ( ) ;
371
+
372
+ Assert . Throws < InvalidOperationException > ( ( ) => p . StartTime ) ;
369
373
try
370
374
{
371
375
p . Start ( ) ;
@@ -376,8 +380,19 @@ public void TestProcessStartTime()
376
380
// Allowing for error in 10 ms.
377
381
long tenMSTicks = new TimeSpan ( 0 , 0 , 0 , 0 , 10 ) . Ticks ;
378
382
long beforeTicks = timeBeforeCreatingProcess . Ticks - tenMSTicks ;
379
- long afterTicks = DateTime . UtcNow . Ticks + tenMSTicks ;
380
- Assert . InRange ( p . StartTime . ToUniversalTime ( ) . Ticks , beforeTicks , afterTicks ) ;
383
+
384
+ try
385
+ {
386
+ // Ensure the process has started, p.id throws InvalidOperationException, if the process has not yet started.
387
+ Assert . Equal ( p . Id , Process . GetProcessById ( p . Id ) . Id ) ;
388
+
389
+ long afterTicks = DateTime . UtcNow . Ticks + tenMSTicks ;
390
+ Assert . InRange ( p . StartTime . ToUniversalTime ( ) . Ticks , beforeTicks , afterTicks ) ;
391
+ }
392
+ catch ( InvalidOperationException )
393
+ {
394
+ Assert . True ( p . StartTime . ToUniversalTime ( ) . Ticks > beforeTicks ) ;
395
+ }
381
396
}
382
397
finally
383
398
{
0 commit comments