A trivial issue it seems.
I have the following code snippet. It seems that the completed event fires before EnumerateFiles actually finishes. For example, if the tb_source.Text ... which is a path like C:\users\<user>\desktop
is set to a folder with say a hundred or so items, all works and reference.throttler_numer_of_files
is correctly populated.
It looks though that if I set that to say, C:\users\<user>
it never gets a chance to find everything before moving on to the completed event. Perhaps it encounters an exception when trying to count the files?
Suggesetions?
// count number of files within source directory (and within subdirectories)
BackgroundWorker bw = new BackgroundWorker();
bw.WorkerReportsProgress = true;
bw.DoWork += new DoWorkEventHandler(
delegate(object o, DoWorkEventArgs args)
{
Thread.Sleep(2000); // give the current UI a moment to load
reference.throttler_number_of_files = Directory.EnumerateFiles(tb_source.Text, "*.*", SearchOption.AllDirectories).Count();
}
);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
delegate(object o, RunWorkerCompletedEventArgs args)
{
// success, clear to launch!
form_throttler_copy throttler_copy = new form_throttler_copy();
throttler_copy.Show();
this.Dispose();
}
);
label_status.Text = "Creating manifest of files... please wait";
picturebox_loading.Visible = true;
bw.RunWorkerAsync();