Control.Invoke vs Tasks with TaskScheduler

I looked through everything and I can not find the answer. Better, worse, or indifferent to use:

{
...
RefreshPaintDelegate PaintDelegate = new RefreshPaintDelegate(RefreshPaint);
Control.Invoke(PaintDelegate);
}

protected void RefreshPaint()
{
    this.Refresh();
}

... or...

Task.Factory.StartNew(() =>
{
    this.Refresh();
},
CancellationToken.None,
TaskCreationOptions.None,
uiScheduler);
+5
source share
2 answers

Assuming that there uiScheduleris a scheduler that will delegate calls in the user interface thread, I would say that the use of these two is functionally indifferent (except that the call to Control.Invoke will block until the call ends, while the call Taskwill not, however, you you can always use Control.BeginInvoketo make them semantically equivalent).

, , Control.Invoke(PaintDelegate) - ; Task , , , , , , , ( , , ). , uiScheduler Control, , , ( , , UI, ).

Control.Invoke , , , , Control , .

, SynchronizationContext ; , , , (Task), , (Control.Invoke).

+3

. , . Control.BeginInvoke, .

( ), .

[]

Task.Factory.StartNew Control.BeginInvoke ( Invoke, ), GUI, . , , , .

0

All Articles