forum

Home / DeveloperSection / Forums / What is Task continuation on UI thread?

What is Task continuation on UI thread?

Anonymous User196710-Oct-2014

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(() =>
            {
                DoLongRunningWork();
            });
 
            Task UITask= task.ContinueWith(() =>
            {
                dispatcher.Invoke(new Action(() =>
                {
                    this.TextBlock1.Text = "Complete";
                }
            });


Updated on 04-Jul-2023
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By