C# 递归搜索方法在运行第二次时需要两倍的时间
我有个小问题。我编写了一个winforms应用程序,递归搜索指定文件夹及其子文件夹中的文件。当我第一次运行应用程序时,该方法需要10分钟来查找100000个文件,但当我第二次执行搜索方法时(不关闭并重新打开windows窗体),它需要两倍的时间。为什么要花双倍的时间 编辑:第一次搜索运行:10分钟,第二次运行:20分钟,第三次运行40分钟 以下是我的搜索方法:C# 递归搜索方法在运行第二次时需要两倍的时间,c#,database,winforms,C#,Database,Winforms,我有个小问题。我编写了一个winforms应用程序,递归搜索指定文件夹及其子文件夹中的文件。当我第一次运行应用程序时,该方法需要10分钟来查找100000个文件,但当我第二次执行搜索方法时(不关闭并重新打开windows窗体),它需要两倍的时间。为什么要花双倍的时间 编辑:第一次搜索运行:10分钟,第二次运行:20分钟,第三次运行40分钟 以下是我的搜索方法: public void dirsearch(string sdir) { this.In
public void dirsearch(string sdir)
{
this.Invoke((MethodInvoker)delegate
{
progressBar.Refresh();
dataGridView.Refresh();
// runs on UI thread
});
foreach (string d in Directory.GetDirectories(sdir))
{
try
{
foreach (string f in Directory.GetFiles(d))
{
if (Regex.IsMatch(f, searchPattern, RegexOptions.IgnoreCase))
{
FileInfo file = new FileInfo(f);
string fileName = file.Name;
string filePath = f;
string user = File.GetAccessControl(filePath).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();
properties.Add(new FileProperties(file.Name, f, file.Length, file.LastWriteTime));
//dataGridView.Refresh();
//progressBar.Refresh();
tryagainpoint:
cmd.CommandText = String.Format("insert into Attribute (Dateiname, Dateipfad, Dateierstellungsdatum, Dateiendung, Grösse, Ersteller, Letztes_mal_bearbeitet, FS) values ('{0}', '{1}', '{2}', '{3}', {4}, '{5}', '{6}', {7})", file.Name, f, file.CreationTime, file.Extension, file.Length, user, file.LastWriteTime, ID);
try
{
cmd.ExecuteNonQuery();
}
catch (OleDbException)
{
if (file.Name.Contains(@"'"))
{
fileName = file.Name.Replace(@"'", @"''");
filePath = f.Replace(@"'", @"''");
goto tryagainpoint;
}
}
finally
{
file = null;
}
}
}
dirsearch(d);
progressBar.MarqueeAnimationSpeed = 0;
}
catch (Exception exc) //Schreibt geworfene Exception in logfile.txt
{
WriteExceptionIntoTxtFile(exc);
continue;
}
}
}
是否清除两次调用之间的集合“属性”。如果不是,则此集合将在第二次调用该函数的开始处包含100000个条目,并在结尾处包含200000个条目。使用分组时,数据网格存在性能问题
顺便说一句:如果在找到每个文件后不刷新datagrid和progressbar,代码会更快 是,我清除两次调用之间的属性集合。刷新是为最终用户准备的,所以他看到有些东西在起作用。我纠正了错误,在找到每个文件后进行刷新,现在速度快了一点,但在第二次运行时仍然需要两倍的时间。gridview中是否激活了分组?wir können auch deutsch schreiben,我是代表rausgenommen,诺尔诺克修女4分钟在劳夫,6分钟在茨威滕·劳夫,在劳芬滴下一滴水。这个程序是用户gar nichts davon的jetzt zwar schneller nur kriegt,它是一个延迟的代理,它的方法是5分钟:)属性对象是什么?此外,还应在insert语句中使用参数(去掉go to)