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
Post a Comment