[Using C# and Windows as platform]
I have a camera that writes JPG files to a local folder in my PC. I want to load each file the camera drops, so I have a FileSystemWatcher that notifies me whenever a new picture is created, but the camera locks the file while it's being written, so if I try to load it just after being notified of its creation, I get an exception saying that the file is locked.
Currently, I have a while loop (with a Thread.Sleep) that retries to load the image every 0.2 seconds, but it feels a bit dirty.
Is there a more elegant way to wait until the lock has been released, so I can load the file being sure that it's no longer used??