Mike Lewis
Programmer
Let me see if I can explain this problem.
I have two programs running at the same time on the same computer. Call them ProgA and ProgB. They are both EXEs.
Once in a while, ProgA writes a value to a table. The table is a DBF file with a single record. ProgA simply updates one field in this record.
At frequent intervals (approx. once per 250 ms), ProgB reads the value. If it has been updated, it takes some action.
The problem is that ProgB isn't seeing the latest value of the field. It seems to be always picking up the original value, as it was when the table was first opened, rather than the updated value.
To illustrate the code (hightly simplified):
The problem is that, when that last bit of code fires, ProgB is always seeing the original value in TheTable.TheField. It's not picking up the updated value. Apparently, VFP is not physically re-reading the record; it has no way of knowing that it's changed.
Can anyone suggest a way of forcing ProgB to physically re-read the record so that it can see the latest value?
In fact, I can do this by closing and re-opening the table immediately before ProgB looks at the field. That solves the problem. Unforunately, it also introduces a lot of overhead. The process takes 40 percent longer as a result.
I'm reasonably sure that ProgA is physically writing the value immediately after the INSERT. If I do a FLUSH or close the table after the INSERT, there's no change in the behaviour of ProgB.
Hope this makes sense.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips, training, consultancy
I have two programs running at the same time on the same computer. Call them ProgA and ProgB. They are both EXEs.
Once in a while, ProgA writes a value to a table. The table is a DBF file with a single record. ProgA simply updates one field in this record.
At frequent intervals (approx. once per 250 ms), ProgB reads the value. If it has been updated, it takes some action.
The problem is that ProgB isn't seeing the latest value of the field. It seems to be always picking up the original value, as it was when the table was first opened, rather than the updated value.
To illustrate the code (hightly simplified):
Code:
* ProgA - Does this very occasionally
UPDATE TheTable SET TheField = .T.
* ProgB - At start of process
USE TheTable IN 0
SELECT TheTable
GO TOP && not really necessary as there's only one rec.
* ProgB - every 250 ms
IF TheTable.TheField
* Do something
ENDIF
The problem is that, when that last bit of code fires, ProgB is always seeing the original value in TheTable.TheField. It's not picking up the updated value. Apparently, VFP is not physically re-reading the record; it has no way of knowing that it's changed.
Can anyone suggest a way of forcing ProgB to physically re-read the record so that it can see the latest value?
In fact, I can do this by closing and re-opening the table immediately before ProgB looks at the field. That solves the problem. Unforunately, it also introduces a lot of overhead. The process takes 40 percent longer as a result.
I'm reasonably sure that ProgA is physically writing the value immediately after the INSERT. If I do a FLUSH or close the table after the INSERT, there's no change in the behaviour of ProgB.
Hope this makes sense.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips, training, consultancy