Open image file with exclusivity
I have an application that will get a list of开发者_开发百科 image filenames and put them in a list.
It will loop over the list and open the file and display it in a picturebox.
There will be up to 50 instances of this applicaiton open on 50 PC's
If the same 2 PC's try to open the image and display it I need one to fail and move onto the next one.
Can I open the file with exclusivity?
If I can't I was thinking of setting the file attribute as archived so that if 2 do try to open the same image hopefully one should see that its archived and move on.
I think what you need is ...
http://msdn.microsoft.com/en-us/library/5h0z48dh.aspx
http://msdn.microsoft.com/en-us/library/system.io.fileshare.aspx
Another way that you could do this is to have a lock file for the image if another App has it open. The lock file can just be a dummy txt file and if it exists then you can assume the file is in use by another process.
Since they're all located on a server.. I'd create an application which would run on the server and handle requests for images. Otherwise, you could end up with old lock files hanging around after program crashes and such, which would then require clean up every x days. The server application can handle all of the locking and such.
精彩评论