I have a problem that I am unable to reproduce in the lab / dev environment.
A beta user is reporting the following error during a file copy.
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\ProgramData....
The line of code in question is:
Directory.CreateDirectory(path);
Now I'm speculating what is going on here is this. Directory.CreateDirectory hands the operation off to the OS. On my test and dev machines there are plenty of resources and the OS creates the directory instantly.
On the beta users machine it is more resource challenged and it doesn't create the directory for a few milliseconds...perhaps even a full second.
In the meantime my application has moved on and is expecting the folder to be there. file.CopyTo(path, true);
My first question is if I am connecting the dots properly.
Second question is if so how should I handle?
sleep the app and monitor OS events for the folder created flag and then proceed. This seems to be a complex solution.
Sleep the app. Spin up a new thread that probes for the folder. When it exists kill thread then proceed. Perhaps not a new thread but same idea on main thread?
Any other ideas?
TIA