I have various apps which read and write small data files. Typically these are an app which interfaces to a sensor and generates results every 10 seconds or so. I delete the existing file and write a new one. Another one then reads these results, say every 10 seconds or so.
Clearly there is the possibility of conflict between these.
At the moment I put the read, write or delete in a Try/Catch structure, where the Catch should wait a short time before trying again.
What is the best way to do this ? I’ve tried doEvents (not recommended I know) and App.SleepCurrentThread, but that seems to not be allowed in a Timer (I get a compiler error for that).
with files i would use this sequence.
write plenty of data into a file, move file into a processing folder (unique filename each),
after processed a file, delete or move into other folder.
No, SQLite won’t help because some of these files have to interoperate with other commercial software.
And the concept of lots of files with unique names being processed and moved around doesn’t help the core problem that, for example, application A writes a small file (<1k), with a known name, every 10 seconds. Application B, and maybe application C read this file with a 10 sec periodicity, but de-synchronised from app A and each other. In each case the applications are running 24/7 and need to have the filenames fixed.
What I would do is have a timer that fires every, say 1 sec. When I see the file appear, make a note of its size, and one second later, if the file size hasn’t changed, attempt to open the file and read it. If that fails, wait another second and retry.