We have a web application that attempts to use some resources on a Samba mount. If the mount has somehow failed, I need a way to quickly detect and report an error, however File.Exists and Directory.Exists are taking 30 seconds to return false when the mount goes away. What is the best way to quickly determine if a mount is available in C#?
The Win32 Windows Networking Functions are the only way to get this information. You should be able to use either WNetGetResourceInformation or WNetGetConnection. I think WNetGetConnection might be the best option. The return values you would be most interested in are:
ERROR_CONNECTION_UNAVAIL
The device is not currently connected, but it is a persistent connection. For more information, see the following Remarks section.
ERROR_NO_NETWORK
The network is unavailable.
All of that aside, I understand the desire to be proactive in being able to read/write from a backup location, but it seems to me that would be more properly handled on the hardware and/or operating system side rather than the application. The hardware and/or operating system is much more likely to be able to detect that a read/write failed or some other network related event occurred and take the appropriate actions.