Hi,

I have the following code (at bottom of thread). All works fine, but it takes about 26 seconds to run through.

The function 'FillDirectoryNodes' is reentrant in order to populate the treeview with all directories on the HDD.

My question is, how can I speed this up?

Also, which is the part that takes the longest? Creating the treeview node, getting the directory info, etc...?

Thanks.

Code:
public partial class FileExplorer
    {
        public FileExplorer()
        {
        }

        public void BuildFileExplorerTreeView(TreeView fe)
        {
            /* Clear the treeview control */
            fe.Nodes.Clear();

            /* Search the system for storage drives */
            DriveInfo[] allDrives = DriveInfo.GetDrives();

            /* For each drive, fill it's files and folders in the treeview */
            foreach (DriveInfo currentDrv in allDrives)
            {
                if (currentDrv.DriveType == DriveType.Fixed)
                {
                    TreeNode node = new TreeNode();
                    node.Text = currentDrv.Name.ToString();
                    fe.Nodes.Add(node);
                    FillDirectoryNodes(currentDrv.Name.ToString(), node);
                }
            }
        }


        private void FillDirectoryNodes(string drv, TreeNode parentNode)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(drv);

            try
            {
                if (dirInfo.Exists)
                {
                    foreach (DirectoryInfo subDirInfo in dirInfo.GetDirectories())
                    {
                        if (subDirInfo.Exists)
                        {
                            TreeNode node = new TreeNode();
                            node.Text = subDirInfo.Name;
                            parentNode.Nodes.Add(node);
                            FillDirectoryNodes(node.FullPath, node);
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
}