[Lazarus] File is locked?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] File is locked?

Leonardo M. Ramé
Hi, I'm checking the contents of an .ini file every 10 seconds (with a
TTimer), the file is modified by another application and I display its
contents in my program.

The problem is the file is locked while the other program is using it
and aparently TIniFile cannot handle this situation, thus raising an
"Unable to open file" error. How can I check if the file is locked
before reading its contents?.

Regards,
--
Leonardo M. Ramé
http://leonardorame.blogspot.com

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] File is locked?

Mark Morgan Lloyd
Leonardo M. Ramé wrote:
> Hi, I'm checking the contents of an .ini file every 10 seconds (with a
> TTimer), the file is modified by another application and I display its
> contents in my program.
>
> The problem is the file is locked while the other program is using it
> and aparently TIniFile cannot handle this situation, thus raising an
> "Unable to open file" error. How can I check if the file is locked
> before reading its contents?.

I don't think you can, because it has to be an atomic operation. Also
the locking behaviour varies a lot depending on operating system
(whatever it is in your case ;-)

I think you'd do better monitoring the file timestamp(s) so that you're
not reparsing it redundantly, and being prepared to handle cases where
IniFile fails. You might be able to request change notifications, but
again that depends heavily on OS.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] File is locked?

leledumbo
Administrator
In reply to this post by Leonardo M. Ramé
> How can I check if the file is locked before reading its contents?

Just handle the exception. Doing nothing in the handler is perfectly fine.
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] File is locked?

Michael Van Canneyt


On Sun, 15 Nov 2015, leledumbo wrote:

>> How can I check if the file is locked before reading its contents?
>
> Just handle the exception. Doing nothing in the handler is perfectly fine.

It is the only possible option.

Michael.

--
_______________________________________________
Lazarus mailing list
[hidden email]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus