Detecting file lock and waiting

Got a problem you cannot solve? Try here.
tofutim
Posts: 176
Joined: Thu Mar 01, 2012 1:16 pm

Detecting file lock and waiting

Postby tofutim » Fri Oct 23, 2015 5:06 am

Hi, how can I detect if a file is locked and wait until it is unlocked? I have a plug-in that begins the process of unlocking but right now it only works if I naively sleep for about a second. (I'm trying to avoid the restart in uninstall.)

In testing, a second is enough time for the lock to release, but 250 ms is too little. However, maybe this will vary depending on the machine. Ideally I would like to wait up to 4-5 seconds but check every 500 ms or so.

FrancescoT
Site Admin
Posts: 5361
Joined: Sun Aug 22, 2010 4:28 am

Re: Detecting file lock and waiting

Postby FrancescoT » Fri Oct 23, 2015 1:19 pm

Dear Tofutim,

as already said on a different post, the best approach is with checking if the file can be opened.
http://stackoverflow.com/questions/876473/is-there-a-way-to-check-if-a-file-is-in-use

You may execute such verification in a loop in order to verify if the file becomes available.

Hope this helps you.

Regards
Francesco Toscano
InstallAware Software

White Papers (HowTos) - http://www.installaware.com/publication ... papers.htm
Publications - http://www.installaware.com/publications-review.htm
InstallAware Help -F1 anywhere in the InstallAware IDE


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 96 guests