I have an app that reads headers of files, I'd like to implement a progress bar but I'm having issues trying to get it to work based off this Microsoft example.
The example works off files copied.
I'd like the bar to progress with each file, with my code below all it does is go to max once all the files have been read. Folders I open to read file headers can have 1 file or 1000's.
I'm lost with this bit, plus I may have the code in the wrong spot...
if (CopyFile(files[x-1]) == true)
I don't think my Threading is working well either, so some advice on it would also be great.
private void btnOpenFile_Click(object sender, EventArgs e)
{
DialogResult result = folderBrowserDialog1.ShowDialog();
if (result == DialogResult.OK)
{
ThreadStart t = delegate {};
listBoxResults.Items.Clear();
string[] files = Directory.GetFiles(folderBrowserDialog1.SelectedPath);
txtFilesFound.Text = files.Length.ToString();
{
string path = folderBrowserDialog1.SelectedPath;
foreach (string filepath in Directory.GetFiles(path, comboFileType.Text, SearchOption.TopDirectoryOnly))
{
foreach (string item in GetHeaderInformation(filepath))
{
this.Invoke(new Action(() => txtUpdate(item)));
// Display the ProgressBar control.
pBar1.Visible = true;
// Set Minimum to 1 to represent the first file being copied.
pBar1.Minimum = 1;
// Set Maximum to the total number of files to read.
pBar1.Maximum = files.Length;
// Set the initial value of the ProgressBar.
pBar1.Value = 1;
// Set the Step property to a value of 1 to represent each file being read.
pBar1.Step = 1;
}
this.Invoke(new Action(() => txtUpdate(filepath + Environment.NewLine)));
this.Invoke(new Action(() => txtUpdate("***************************************************************************")));
for (int x = 1; x <= files.Length; x++)
//if(CopyFile(files[x-1]) == true)
//{
// Perform the increment on the ProgressBar.
pBar1.PerformStep();
//}
}
};
new Thread(t).Start();
}
}
Any help would be appreciated.
Perhaps this example might be more beneficial.