Noro
Noro

Reputation: 1663

Which WINAPI function I must use to know if a file is blocked by another process?

Which WINAPI function can I use to find out if a file has been opened by another process?

I use C# and sometimes get the exception "The process cannot access the file because it is being used by another process".

Upvotes: 0

Views: 199

Answers (2)

Jorge Córdoba
Jorge Córdoba

Reputation: 52133

Simple try catch should do (catch specific exception though)... if you don't expect the file to be being used then it's ok to just handle the "exceptional" behavior.

In addition, try opening the file with the permissions you need, if you only need to read, open file for reading, another process might just be reading and that don't have to be a problem if you don't try to write it.

Upvotes: 2

Raj
Raj

Reputation: 1770

How about attempting to open the file exclusively inside a try/catch bloack and then trapping the file used by another process exception to check of the file is busy.

Upvotes: 0

Related Questions