我正在尝试搜索包含大量文件夹且名称包含特定字符串的文件夹中的文件。
我能够做到,但要花费我大约[[2分钟,这对我来说是太多时间。
这是功能: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);
}
}
}
这是我使用此功能的地方:
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."; }
目标是像在Windows中进行搜索一样花费我。4-7秒
但是有个好消息:您
可以]也这样做。有几种方法可以达到相似的响应时间,有些更快,有些更精确。
例如,您可以: