L
L
littleguga2015-10-07 18:55:01
.NET
littleguga, 2015-10-07 18:55:01

How to know that a Task has completed its work?

Did I understand correctly that ContinueWith() is executed after the completion of the task?
Is this code correct:

Task.Factory.StartNew(() =>
{
  //здесь какой-то наш код
}).ContinueWith((t) => {

  //выводим в поток gui сообщение об успешном завершении task'a
  result.Text = "saved: 512";
  result.ForeColor = System.Drawing.Color.Green;

}, TaskScheduler.FromCurrentSynchronizationContext());

Thanks in advance for your informative response!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2015-10-07
@littleguga

Yes, you understood correctly. At first glance, there is no problem in the code (if it is executed from a GUI thread and FromCurrentSynchronizationContext() gives the context of the GUI thread). Is something not working?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question