I sometimes get false negatives when I check if a directory on a network path exists.
When I check if the folder exists the method returns 'true' most of the time. Sometimes it switches to 'false' and reports 'false' for every call for about 5 seconds.
I think it changes to 'false' when someone who hasn't accessed the network drive for a while (maybe 15 minutes) accesses it for the first time. The network drive is not offline during these 5 seconds. I'm still able to navigate it in Windows Explorer. Therefore I am not sure that this really causes the false negatives.
Even the Directory.CreateDirectory() method fails sometimes with an error stating the directory already exists. But the docs say it only tries to create the directory if it does not already exist.
It doesn't matter whether I use
new DirectoryInfo("PATH").Exists;
Directory.Exists("PATH");
- Upon request in the comments I also tried
var di = new DirectoryInfo("PATH");
di.Refresh();
di.Exists;
And which format for the path I use
N:\MyFolder
(N: is the same previousely mapped network drive)\\192.168.1.10\MyShare\MyFolder
I saved the credentials to this server in Windows Credentials Manager.
Does anyone have any idea what could cause this inconsistency?