I have a winform that monitors several folders for new/changed files, and then parses them and inserts them into a database. This process can take several minutes or longer depending on the length of the file. Basically, each time a new file is dropped in, I'd like my app to check if there are any processes currently busy, and if not, then create a new thread and run the method.
public partial class Form1 : Form
{
private BackgroundWorker backgroundWorker1 = new BackgroundWorker();
public eBoardMonitor()
{
InitializeComponent();
}
private void btnMonitor_Click(object sender, EventArgs e)
{
this.backgroundWorker1.DoWork +=
new DoWorkEventHandler(backgroundWorker1_DoWork);
this.backgroundWorker1.RunWorkerCompleted +=
new System.ComponentModel.RunWorkerCompletedEventHandler(
this.backgroundWorker1_RunWorkerCompleted);
this.backgroundWorker1.RunWorkerAsync();
localWatcher.EnableRaisingEvents = true;
pdaWatcher.EnableRaisingEvents = true;
}
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
fileWatch.CheckExisting();
}
private void backgroundWorker1_RunWorkerCompleted(
object sender, RunWorkerCompletedEventArgs e)
{
this.txtLog.Text += "Completed"
}
public partial class Form1 : Form
{
private BackgroundWorker backgroundWorker1 = new BackgroundWorker();
public eBoardMonitor()
{
InitializeComponent();
}
private void btnMonitor_Click(object sender, EventArgs e)
{
this.backgroundWorker1.DoWork +=
new DoWorkEventHandler(backgroundWorker1_DoWork);
this.backgroundWorker1.RunWorkerCompleted +=
new System.ComponentModel.RunWorkerCompletedEventHandler(
this.backgroundWorker1_RunWorkerCompleted);
this.backgroundWorker1.RunWorkerAsync();
localWatcher.EnableRaisingEvents = true;
pdaWatcher.EnableRaisingEvents = true;
}
void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
fileWatch.CheckExisting();
}
private void backgroundWorker1_RunWorkerCompleted(
object sender, RunWorkerCompletedEventArgs e)
{
this.txtLog.Text += "Completed"
}