I have a GUI that needs to load images throughout the day as things change.
These (around 80k of them) are stored on a separate server which I access via a shared drive. Often some of the images are missing.
I have also been trying to find an issue where the GUI locks up for seconds. Recently the server had its IP address changed and so the mapping was invalid. I noticed this caused the GUI to lock up for up to 30 seconds or so and tracing the problem discovered that the call to File.Exists was taking a long time to return for some (but not all?) of the checks.
I believe that there can be an issue with File.Exists in that if it cannot find the file it creates an internal exception and this slows things down. I have no choice but to do the dynamic loading, of the images, on the main thread.
I have read that the following would be a better method given the limitations
[DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
private extern static bool PathFileExists(StringBuilder path);
// A StringBuilder is required for interops calls that use strings
StringBuilder builder = new StringBuilder();
bool exists = PathFileExists(builder);
Is it worth using this method and if so what would be the best way to put the call into my utility class (static methods)?