The most examples are with a for loop, and they work, and explain how a BackgroundWorker works. But how do I use a ProgressBar for a method that converts data? It takes a few minutes and I want to show the user the progress of the method.
private void DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 100; i++)
{
Thread.Sleep(100);
backgroundWorker.ReportProgress(i);
}
}
Here you give always I to update the value. But what if I want to do this?
private void DoWork(object sender, DoWorkEventArgs e)
{
ConvertDataMethod();
backgroundWorker.ReportProgress(i); <- What do I do here??
}
private void ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar.Value = e.ProgressPercentage;
}