Page 1 of 1

Detecting file lock and waiting

Posted: Fri Oct 23, 2015 5:06 am
by tofutim
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.

Re: Detecting file lock and waiting

Posted: Fri Oct 23, 2015 1:19 pm
by FrancescoT
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