Use ProgressBar, BackgroundWorker & LisBox to display all the files w/i the directory
Use ProgressBar, BackgroundWorker & LisBox to display all the files w/i the directory
and simulation of processing each file
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
namespace WindowsFormsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, System.EventArgs e)
{
// Start the BackgroundWorker.
progressBar1.Minimum = 0;
progressBar1.Maximum = GetProgressMax();
backgroundWorker1.RunWorkerAsync();
}
protected int GetProgressMax()
{
int i = 0;
DirectoryInfo di = new DirectoryInfo(@"C:\Documents and Settings\user\My Documents\eric scheduler\ci review\Debug-Full\ContractReviewLog");
if (di.Exists)
{
i = di.GetFiles("*.txt").Length;
}
return i;
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
/* for (int i = 1; i <= 100; i++)
{
// Wait 100 milliseconds.
Thread.Sleep(100);
// Report progress.
backgroundWorker1.ReportProgress(i);
}*/
DirectoryInfo di = new DirectoryInfo(@"C:\Documents and Settings\user\My Documents\eric scheduler\ci review\Debug-Full\ContractReviewLog");
if (di.Exists)
{
int i = 0;
foreach (FileInfo fi in di.GetFiles("*.txt"))
{
backgroundWorker1.ReportProgress(i);
i++;
Thread.Sleep(100);
listBox1.Items.Add(fi.Name);
}
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
// Change the value of the ProgressBar to the BackgroundWorker progress.
progressBar1.Value = e.ProgressPercentage;
// Set the text.
//this.Text = e.ProgressPercentage.ToString();
label1.Text = "percent: " + e.ProgressPercentage.ToString() + "%";
label1.Refresh();
}
}
}
