file in use by another program

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello everyone,
is there a way to check if a file is in use by another program. One
possibility would be to poll the file for an exclusive lock, but this has
very bad consequences for the performance of my program.

Thanks, Holger
 
Holger,

Before you want to use the file, you could try and access the file
through a call to the CreateFile API function. It will be more specific
with it's return value in indicating whether or not it is in use by someone
else.

Hope this helps.
 
Ive seen this discussed before and the usual answer is for your application
simply catch (and handle) any exceptions caused by file access -since there
might be other reasons why a file does not open (e.g. permissions). Simply
doing any pre-checks on the file is still no guarantee that a file is going
to open at the exact moment of the request -so you would still need to catch
and handle potential exceptions anyway.

--
Best Regards,

Mark

Mark Broadbent

mcad,mcdba,mcse+i
emailto: newsgroupsATmettayyaDOTgotadslDOTcoDOTuk
remove AT with '@' and DOT with '.' -please do not send spam or address will
be changed!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top