c# - Task continuation on UI thread -


is there 'standard' way specify task continuation should run on thread initial task created?

currently have code below - working keeping track of dispatcher , creating second action seems unnecessary overhead.

dispatcher = dispatcher.currentdispatcher; task task = task.factory.startnew(() => {     dolongrunningwork(); });  task uitask= task.continuewith(() => {     dispatcher.invoke(new action(() =>     {         this.textblock1.text = "complete";      } }); 

call continuation taskscheduler.fromcurrentsynchronizationcontext():

    task uitask= task.continuewith(() =>     {      this.textblock1.text = "complete";      }, taskscheduler.fromcurrentsynchronizationcontext()); 

this suitable if current execution context on ui thread.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -