c# - given a Task instance, can I tell if ContinueWith has been called on it? -


given task instance, how can tell if continuewith has been called on it? want know if i'm last task executing in chain.

task task = task.fromresult(); void somemethod(var x) {    task = task.continuewith(previous => {        if (task.continuewith called) return;        // x...    } } 

if meant multiple continuations. possible solution may this.

class program     {         public class taskstate         {             public bool ended { get; set; }         }          static void main(string[] args)         {             var task = task.fromresult("stackoverflow");             var state = new taskstate();             task.continuewith((result, continuationstate) =>             {                 console.writeline("in first");               }, state).continuewith((result, continuationstate) =>             {                 if (!state.ended)                     console.writeline("in second");                 state.ended = true;              }, state).continuewith((result, continuationstate) =>             {                 if (!state.ended)                     console.writeline("in third");                 state.ended = true;              }, state);             console.readline();         }      } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -