I'm trying to search files in a folder that has a lot of folders, with a name that contain specific string.
I'm able to do it but it's taking me about 2 minutes and this is too much time for me.
This is the function:
private void Search()
{
foreach (var file in Directory.EnumerateFiles(@"P:\system\mail\", "*" + textBox1.Text + "*.pdf*", SearchOption.AllDirectories))
{
this.Invoke(new MethodInvoker(delegate ()
{
listBoxControl1.Items.Add(file);
}));
if (XtraMessageBox.Show("Open the file: " + file + " ?", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
Process.Start(file);
}
}
}
And this is where I'm using the function:
private async void simpleButton1_Click(object sender, EventArgs e)
{
labelControl1.Text = "Status: Please wait . . .";
Stopwatch watch = new Stopwatch();
watch.Start();
await Task.Run(() => Search());
watch.Stop();
labelControl1.Text = "The process done in " + watch.Elapsed.TotalMinutes.ToString() + " minutes.";
}
The goal is to do it like the search in windows that takes me 4-7 seconds.