c# - Prevent a Task Continuation -


i'm using task continuations long running operation on winform project.

var task1 = task.factory.startnew(() => dosomework());  var task2 = task1.continuewith(result => dosomemorework(), taskcontinuationoptions.onlyonrantocompletion);  var task3 = task2.continuewith(result => dofinalwork(), taskcontinuationoptions.onlyonrantocompletion); 

i want continue task3 if conditions met on dosomemorework() function executes on task2. how can done?

from msdn

a user-defined value can passed antecedent continuation in result property, output of antecedent can serve input continuation

so 1 way in task3, check result task2 before doing work.

var task2 = task1.continuewith(result => dosomemorework(), taskcontinuationoptions.onlyonrantocompletion); var task3 = task2.continuewith(x => dofinalwork(x.result)); 

where result returned task2 determines happens in task3.

edit solution cancel task2 if conditions not met within operation. continuation task not scheduled.

from msdn

to prevent continuation executing if antecedent canceled, specify notoncanceled option when create continuation.

so task3 definition becomes

var task3 = task2.continuewith(result => dofinalwork(), taskcontinuationoptions.notoncancelled); 

Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -