We have two Windows Forms: FormSqlUpdater
and FormReader
. FormSqlUpdater
updates an SQL table and FormReader
reads from that same SQL table. This means that FormReader
needs to be polling the database continually; When FormSqlUpdater
changes the SQL table, the change is reflected through a TextBox
in FormReader
. I would like to make this as real-time as possible.
So many of the suggestions have been to use a Timer
. Considering that this needs to be as real-time as possible, I have a feeling that if I set the Timer
to poll the database too often (i.e., every three seconds) then this lag will be noticed by the user. Also, if the query takes too long for whatever reason, this lag will also be noticed by the user. And if I set the Timer for too long, then the Forms won't be synchronized. Either way, I don't feel too comfortable with a Timer.
So I was thinking of using the FileSystemWatcher
in FormReader
; when FormSqlUpdater
updates the DB, it will write to a text file. Once FileSystemWatcher
in FormReader
notices that the text file has been changed, then FormReader
will update itself.
At least for me, it seems that using FileSystemWatcher
this way is possibly a better alternative.
What are your thoughts?
Thanks.