I am writing two applications: one to write data to a file and another to read data from a file. These programs will be running at the same time. My fear is that one app might write to the file some data and then the other app tries to read it before it is finished. This may lead to missing data, scrambled data, or crashes.
Not sure what I can do… is there a way to lock the file while in use(set from each app)?
(Note: I will not be using a database.)
I am using VS C++ 6.0… this is one of the companies requirements due to older software.
You should use some kind of synchronization between the two processes. For example create a named event (CreateEvent with a lpName that is not NULL). Initialize the event to
This way when one of the process wants to use the file it should first WaitForSignleObject on the event. When it is done it should SignalEvent thus allowing the other process to access the file.
BTW – VC6 is a really bad compiler. You should consider upgrading to a newer version.