I would like to know, what is the best/safest way to access the main UI thread from another thread.
Should i use Dispatcher.BeginInvoke
?
_cancelationTokenSource = new CancellationTokenSource();
new Task(() =>
{
Dispatcher.BeginInvoke((Action)(() =>
{
//process data
}));
}, _cancelationTokenSource.Token, TaskCreationOptions.LongRunning).Start();
or should i use Dispatcher.Invoke
?
_cancelationTokenSource = new CancellationTokenSource();
new Task(() =>
{
Dispatcher.Invoke((Action)(() =>
{
//process data
}));
}, _cancelationTokenSource.Token, TaskCreationOptions.LongRunning).Start();
What is the main difference between the 2 Invoke
methods?
What will the performance impact be when using BeginInvoke
and Invoke
?
Most important, i would like to keep my UI responsive.