@@ -213,14 +213,17 @@ public ITask Finally<T>(T taskToContinueWith)
213
213
return continuationOnAlways ;
214
214
}
215
215
216
+ /// <summary>
217
+ /// This does not set a dependency between the two tasks. Instead,
218
+ /// the Start method grabs the state of the previous task to pass on
219
+ /// to the next task via previousSuccess and previousException
220
+ /// </summary>
221
+ /// <param name="handler"></param>
216
222
internal void SetFaultHandler ( TaskBase handler )
217
223
{
218
- if ( Task . Status == TaskStatus . Created )
219
- this . continuationOnFailure = handler ;
220
- else
221
- Task . ContinueWith ( t => handler . Start ( t ) , Token ,
222
- TaskContinuationOptions . OnlyOnFaulted ,
223
- TaskManager . GetScheduler ( handler . Affinity ) ) ;
224
+ Task . ContinueWith ( t => handler . Start ( t ) , Token ,
225
+ TaskContinuationOptions . OnlyOnFaulted ,
226
+ TaskManager . GetScheduler ( handler . Affinity ) ) ;
224
227
DependsOn ? . SetFaultHandler ( handler ) ;
225
228
}
226
229
@@ -260,6 +263,11 @@ protected void Run()
260
263
}
261
264
}
262
265
266
+ /// <summary>
267
+ /// Call this to run a task after another task is done, without
268
+ /// having them depend on each other
269
+ /// </summary>
270
+ /// <param name="task"></param>
263
271
protected void Start ( Task task )
264
272
{
265
273
previousSuccess = task . Status == TaskStatus . RanToCompletion && task . Status != TaskStatus . Faulted ;
@@ -365,6 +373,11 @@ protected virtual void RaiseOnEnd()
365
373
//Logger.Trace($"Finished {ToString()}");
366
374
}
367
375
376
+ protected void CallFinallyHandler ( )
377
+ {
378
+ finallyHandler ? . Invoke ( ) ;
379
+ }
380
+
368
381
protected virtual bool RaiseFaultHandlers ( Exception ex )
369
382
{
370
383
if ( catchHandler == null )
@@ -565,7 +578,10 @@ protected virtual void RaiseOnEnd(TResult result)
565
578
{
566
579
OnEnd ? . Invoke ( this , result ) ;
567
580
if ( continuationOnSuccess == null && continuationOnFailure == null && continuationOnAlways == null )
581
+ {
568
582
finallyHandler ? . Invoke ( result ) ;
583
+ CallFinallyHandler ( ) ;
584
+ }
569
585
//Logger.Trace($"Finished {ToString()} {result}");
570
586
}
571
587
0 commit comments