I’ve worked on several desktop applications that used tables to group information from a database table. But keeping this information updated has made me hack different solutions like a working thread that updates a table executing a query every X seconds, or simply a button to refresh the view. I have even seen an app that would refresh a table using mouse movement events. So my question is, which is your preferred method. Is there a ‘perfect’ way of achieving this that I sleep over at college? Thanks for the responses people.
I’ve worked on several desktop applications that used tables to group information from a
Share
What are you trying to accomplish?
Is it some sort of real time monitoring application like stock trading, plant monitoring software or do you have grid in some CRUD application that you want automatically update?
If this is a crud application, then first thing I would do is to check requirements:
If you really really need approach you described, then you did fine – you can use either timer or some other event(button, mouse move, …) to refresh data. Of course, constant requerying will become performance problem as number of users raise.
If it is real time monitoring software with lots of data than you should not put database in center of system. You should have central service that your clients connect to over TCP (or some similar protocol). Central service should keep latest state of system (plus maybe some history). Clients can attach to service and service should notify clients when there is new data, so that you avoid constant polling. Database should be used as log that application uses for analysis of past events, but not for real time display.
Edit :
Regarding Andrej’s answer: I am not sure if this resolves your problem. Observer pattern is usually implemented with subscribe/notify mechanism, so that data source can notify all observers when data changes. Problem is that RDBMS’s usually do not have mechanism that can notify you about data change. Even if they have, it is not practical because there can be large number of changes in short period of time. Think of tens or hundreds of updates in second – how often RDBMS should notify clients about change? What if there are hundreds of clients with slow network? When you have more than one user, things become complicated.
Databinding works in process – you cannot bind your grid directly to table in database. You first need to get data to your application into some object that can be bound to GUI (datasets, lists, …)