【发布时间】:2013-07-06 15:50:54
【问题描述】:
我想尝试制作自己的文件浏览器。我有一个算法来枚举所有驱动器中的所有目录。但它运行得太慢了。这是我的代码:
public ExplorerForm()
{
InitializeComponent();
this.SuspendLayout();//Without this, it will be far more slow again!
string[] a = System.IO.Directory.GetLogicalDrives();// a is used for drive array
for(int b = 0; b < a.Length; b++)//B is an enumerator. Ussually it is only one letter
{
//Defining the node
TreeNode c = new TreeNode();//c i place for TreeNode
c.Text = a[b].Substring(0,2);
c.Tag = a[b];
ApplyNodes(a[b], ref c);
if(c != null) tv.Nodes.Add(a)
}
this.ResumeLayout(false);
}
private void ApplyNodes(string a, ref TreeNode b)//a=directory, b applied TreeNode
{
try{
List<string> c = new List<string>(Directory.EnumerateDirectories(a);//c = directories
if (c.Count == 0 ) return;
for(int d = 0; d < c.Count; d++)//d = enumerator.
{
TreeNode e = new TreeNode();//e = TreeNode
var z = c[b].Split(Convert.ToChar("/"));
e.Text = z[z.Length-1]
e.Tag = c[b];
ApplyNodes(c[b], e)
if(e != null) b.Nodes.Add(e)
}
}catch (UnauthorizedAccessException){
}catch (IOException){ //For test, It is removed. and my E: is not ready
}
}
电视是我的控制。 它运行得很慢。当我删除选择的行时会显示,抛出 IOException 需要 10 多秒的时间。帮助我如何改进枚举。使用线程和部分更新除外。如果以后不能修复,请告诉我原因。
【问题讨论】:
-
Directory Enumeration too slow- 购买硬盘。 -
错误..是的。这就是为什么您不枚举所有目录的原因。您只需在需要时显示您需要的内容。
-
其他文件管理器使用相同的慢速界面。仔细观察它们的运作方式。
-
帮助我如何改进枚举。除了使用线程和部分更新之外。您基本上是在说“这很慢。在没有公认的使其更快的技术的情况下使其更快。”您想要解决问题的学术解决方案还是实用解决方案?
-
不,Windows 的文件资源管理器只需要两秒钟 打开 Windows 资源管理器并单击文件夹浏览器左侧的
C:驱动器。按小键盘上的*键。数到一密西西比,然后数到两密西西比。完成了吗?否。如果您想减少重绘的影响,请将窗口最小化。
标签: c# performance