I want to try making own file explorer. I have a algorithm to enumerate all directories in all drives. But it runs far too slowly. Here is my code:
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
}
}
tv is my control. It is run very slowly. It is indicated when I remove choosen line, It will take time more than 10s to throw an IOException. Help me how to improve the enumeration. This is except using thread and partial update. If can't be later fixed, tell me why.