I have the following code:
progressBar1.Minimum = 0;
progressBar1.Maximum = Results.Count;
foreach (MyClass cls in Results)
{
progressBar1.Value += 1;
// Go to DB and get large quantity of data
cls.GetHistoryData();
}
What I’d like to do is shift the processing to another thread so that progressBar1 updates correctly. I’ve found an article that implies that I should be able to use the Invoke method on the progress bar, but there doesn’t appear to be one.
If you bind the progressbar to a data property you do not need to switch the thread context manually. The WPF binding engine will do this automatically for you.
And then in your thread:
In most cases this is much cleaner and less error prone than marshalling on your own using Dispatcher.Invoke or BackgroundWorker