I setup the following test based on another project im working on and cant seem to get the progress bar to show the status as its copying the files
BackgroundWorker workerThread = null;
public Form2()
{
InitializeComponent();
InstantiateWorkerThread();
}
private void InstantiateWorkerThread()
{
workerThread = new BackgroundWorker();
workerThread.ProgressChanged += WorkerThread_ProgressChanged;
workerThread.DoWork += WorkerThread_DoWork;
workerThread.WorkerReportsProgress = true;
workerThread.WorkerSupportsCancellation = true;
}
private void WorkerThread_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
lblStopWatch.Text = ("Progress: " + e.ProgressPercentage.ToString() + "%");
progressBar1.Value = e.ProgressPercentage;
}
private void WorkerThread_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 0; i <= 100; i++)
{
// Report progress to 'UI' thread
workerThread.ReportProgress(i);
// Simulate long task
copytest();
}
}
private void btnStart_Click(object sender, EventArgs e)
{
workerThread.RunWorkerAsync();
}
private void copytest()
{
string pathFrom = @"C:\Test\WA8\CLR";
string pathTo = @"C:\Test\Test";
foreach (String file in Directory.GetFiles(pathFrom))
{
// Copy the current file to the new path.
File.Copy(file, Path.Combine(pathTo, Path.GetFileName(file)), true);
}
}
I am using this how to for my example i found online
I also tried this example with my code and not working Second how to attempted
What am i doing wrong with this setup? The copy works and takes about 30 seconds because there is only 50 files..
My form is simple, Button, Progressbar and Label

Also i guess to correct my earlier statement below, the Label text does show up, the percentage that should be shown does not.. So the label is being displayed as seen in the screen shot
So something interesting, i took a screen shot of the form earlier which meant i had to run the application to show the label in the shot, well since i didnt close the application while i was posting, i came back to it after my earlier post and found that things updated, but not correctly. All 59 files were copied over, but even though the copy had already completed, the the progress bar only showed partially green and the label reflected 5%. Why would the process run, complete and the progress bar only reflect 5% complete?

copytest(), then of course the debugger tells me about it. Is a debugger attached? Have you changed any properties ofprogressBar1in the designer? - rfmodulatorcopytest()method completes without an exception). If you have a problem, the code must be different. You'll need to include a good minimal reproducible example that reliably reproduces the problem. Note that that may require including all initialization normally done in the*.Designer.csfile, in case you've made an error configuring the program in the Designer. - Peter Duniho