@@ -300,6 +300,8 @@ private void TaskRun()
300
300
{
301
301
try
302
302
{
303
+ ManualResetEventSlim childMre = new ManualResetEventSlim ( initialState : false ) ;
304
+
303
305
if ( _createChildTask )
304
306
{
305
307
TaskCreationOptions childTCO = ( TaskCreationOptions ) ( int ) _childCreationOptions ;
@@ -313,18 +315,21 @@ private void TaskRun()
313
315
childTCO = TaskCreationOptions . AttachedToParent ;
314
316
}
315
317
316
- _childTask = new Task ( ChildTaskRun , null , _childTaskToken , childTCO ) ;
318
+ _childTask = new Task ( ChildTaskRun , childMre , _childTaskToken , childTCO ) ;
317
319
318
320
if ( _childTask . Status != TaskStatus . Created )
319
321
{
320
322
Assert . True ( false , string . Format ( "Expecting Child Task status to be Created while getting {0}" , _childTask . Status . ToString ( ) ) ) ;
321
323
}
324
+
325
+ _childTask . Start ( ) ;
326
+
322
327
if ( _testAction != TestAction . CancelTask && _testAction != TestAction . CancelTaskAndAcknowledge )
323
328
{
324
329
//
325
- // if cancel action, start the child task after calling Cancel()
330
+ // if cancel action, release the child task after calling Cancel()
326
331
//
327
- _childTask . Start ( ) ;
332
+ childMre . Set ( ) ;
328
333
}
329
334
}
330
335
@@ -336,19 +341,14 @@ private void TaskRun()
336
341
switch ( _testAction )
337
342
{
338
343
case TestAction . CancelTask :
339
- if ( _createChildTask )
340
- {
341
- _childTask . Start ( ) ;
342
- }
343
344
_taskCts . Cancel ( ) ;
345
+ childMre . Set ( ) ;
344
346
345
347
break ;
346
348
case TestAction . CancelTaskAndAcknowledge :
347
- if ( _createChildTask )
348
- {
349
- _childTask . Start ( ) ;
350
- }
351
349
_taskCts . Cancel ( ) ;
350
+ childMre . Set ( ) ;
351
+
352
352
if ( _taskCts . Token . IsCancellationRequested )
353
353
{
354
354
throw new OperationCanceledException ( _taskCts . Token ) ;
@@ -367,6 +367,8 @@ private void TaskRun()
367
367
368
368
private void ChildTaskRun ( object o )
369
369
{
370
+ ( o as ManualResetEventSlim ) ? . Wait ( ) ;
371
+
370
372
if ( _childTask . Status != TaskStatus . Running )
371
373
{
372
374
Assert . True ( false , string . Format ( "Expecting Child Task status to be Running while getting {0}" , _childTask . Status . ToString ( ) ) ) ;
0 commit comments