Hi,
I have built a treeview control that lists the directory structure of any drive or folder. However, if you select a drive, or something with a large structure of folders and sub folders the control takes a long time to load and in some instances shows an MDA ContextSwitchDeadlock message. I have disabled the MDA deadlock error message and it works, but I don't like the time factor and the app looking like it has locked. How can I modify the code so that it keeps pumping messages, and rather than buffering the whole view and passing it in its entirety to the control, is there a way of pushing it, to the control, as it is being built?
//Call line
treeView1.Nodes.Add(TraverseDirectory(source_computer_fldbrowser.SelectedPath));
private TreeNode TraverseDirectory(string path)
{
TreeNode result;
try
{
string[] subdirs = Directory.GetDirectories(path);
result = new TreeNode(path);
foreach (string subdir in subdirs)
{
TreeNode child = TraverseDirectory(subdir);
if (child != null) { result.Nodes.Add(child); }
}
return result;
}
catch (UnauthorizedAccessException)
{
// ignore dir
result = null;
}
return result;
}
Thanks R.