My company\'s code base contains the following C# line:
bool pathExists = Directory.Exists(path);
At runtime, the string path
happ
There is no way to change the behavior of Directory.Exists
for this scenario. Under the hood it's making a synchronous request over the network on the UI thread. If the network connection hangs because of an outage, too much traffic, etc ... it will cause the UI thread to hang as well.
The best you can do is make this request from a background thread and explicitly give up after a certain amount of time elapses. For example
Func func = () => Directory.Exists(path);
Task task = new Task(func);
task.Start();
if (task.Wait(100)) {
return task.Value;
} else {
// Didn't get an answer back in time be pessimistic and assume it didn't exist
return false;
}