Home > DeveloperSection > Forums > What is Task continuation on UI thread?
Goti Bandu

Total Post:119

Posted on    October-10-2014 1:40 AM


 1 Reply(s)
 929  View(s)
Rate this:

Is there a 'standard' way to specify that a task continuation should run on the thread from which the initial task was created?

Currently I have the code below - it is working but keeping track of the dispatcher and creating a second Action seems like unnecessary overhead.

dispatcher = Dispatcher.CurrentDispatcher;

            Task task = Task.Factory.StartNew(() =>





            Task UITask= task.ContinueWith(() =>


                dispatcher.Invoke(new Action(() =>


                    this.TextBlock1.Text = "Complete";



Kamlakar Singh
Kamlakar Singh

Total Post:194

Posted on    October-10-2014 1:41 AM

Call the continuation with TaskScheduler.FromCurrentSynchronizationContext():

Task UITask = task.ContinueWith(() =>


                this.TextBlock1.Text = "Complete";

            }, TaskScheduler.FromCurrentSynchronizationContext());

Don't want to miss updates? Please click the below button!

Follow MindStick