I assume that if the file is used somewhere else, the code to open it would produce an error. A simple solution might then be to use a try - catch block.
>Hi all,
>
>What is the proper way to determine if a file is locked by another process?
>
>I have a Windows service that handles File Create events from a File System Watcher. When a new file is created, it kicks off a new thread and goes back to sleep. The thread has a timer so it can sleep until the file has been completely written to disk. I am currently using the file size to determine when the file is no longer growing. That worked for another project where files were being created from an ftp download, but it doesn't work in this particular case. The files I'm dealing with now are being uploaded to a server as they are being recorded (streaming video). I think the file size is being reported as 0 until the file write is done (about 2 hours). Is there a way I can just ask the file if it's locked by another process? Then, I can just keep sleeping until the file is unlocked.
>
>TIA,
>Chad
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)