Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-11

File is locked?

4 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

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,

Reply by email

Mark Morgan Lloyd
to Leonardo M. Ramé
Leonardo M. Ram? wrote 8 lines
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]

Reply by email

Michael Van Canneyt
to leledumbo
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.

Reply by email