Alternative to polling database in Windows Form?

谁都会走 提交于 2019-12-12 03:47:58

问题


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.

来源:https://stackoverflow.com/questions/37993243/alternative-to-polling-database-in-windows-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!