I am writing a program that shows a drive/directory tree which then populates a files list (ListView). If the user tries to select a network drive that isn't available, the program stops responding to user input for about 25 seconds.
I think the program hangs on a call to DirectoryInfo.
so I have something like this:
private void DirCheck( string startPath) {
var directoryInfo = new DirectoryInfo(startPath);
directoryInfo.GetDirectories();
}
then I have two scenarios to try to get around the delay
Scenario 1:
I call it like:
Task Test = Task.Factory.StartNew(() =>
DirCheck("\\netstuff\shared");
On this Task call, I tried to omit any wait for the conclusion of the tasks.
Scenario 2:
private void TreeWorker(object sender, DoWorkEventArgs e)
{
string strVal;
strVal = (string)e.Argument;
DirCheck(strVal);
}
The problem is that the program still hangs for 25 seconds.
In the complete code, I am looking for an exception to occur if the drive can't be found.
The two questions then are:
1) Is there a better way to verify access to the remote drive such that there is no delay to the responsiveness of the user interface?
2) Does the GetDirectories method invariably tie-up the whole process, even if called from within a thread of the process?
Thanks.