Question

I have seen these questions, and I am not asking the same question:
Is there a way to check if a file is in use?
and
How to check if file is in use in c#?

I am asking the question, how to detect if file is open in another process. It's the same question those other guys asked, but the answers they got tell them to see if they can get exclusive lock on the file, in order to imply the file being open in another process. I do not wish to get exclusive lock on a file, because I don't want to potentially interfere with the operation of the other processes.

Also, different OSes might behave differently - some OSes might support things like filesystem-level or block-level snapshots or shadow copies, which might allow you to get exclusive lock on a file, even if some other process has the file open for reading.

One person in the other questions said you can test all the open file handles in the system. Is that the only way? And if so, how would one go about doing it in C#? I don't see any obvious native .Net class to browse all the open file handles in the system.

Était-ce utile?

La solution

See if this helps

It has detailed information on this problem

http://www.codeproject.com/Questions/531409/fileplusisplususedplusbyplusanotherplusprocessplus

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top