This method also should not be called on you non-UI thread but invoked on the UI thread using
Dispatcher.Invoke
or
Dispatcher.BeginInvoke
. You cannot call anything on UI from non UI thread.
You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[
^],
Control events not firing after enable disable + multithreading[
^].
[EDIT]
This is how to work with delegate needed for invocation properly:
void UpdateProgressBar(Dispatcher dispatcher, ProgressBar progressBar, double value) {
dispatcher.BeginInvoke(
new Action<ProgressBar, double>(
(progressBarInstance, newValue) => {
progressBarInstance.Value = newValue;
}), progressBar, value);
}
The body of the anonymous delegate instance comes between "{}" above.
—SA