AymAn AbuOmar
AymAn AbuOmar

Reputation: 423

Is there better way than this way to update listview every 1 second from DataBase?

i have in my application a listview that shows the transport events , this listview should be updated every one second , to follow up the events. i simply do that by a timer (1000 interval) that declare one connetion object,dataReader... and then fill the listview ,finally, i dispose the connection and another objects (this is every one timer tick).

Now, is there any better way to do that ? maybe better for performance,memory or other somethings?

i'am not expert, so i thinked maybe that is declaring many conncetions every second may making some memory problems :) (correct me if that is wrong)

DataBase Access 2007 VS 2012

Thank You.

Upvotes: 1

Views: 159

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726849

Assuming that you are using ADO.NET to access your database, your access model should be fine, because .NET uses connection pooling to minimize performance impacts of closing and re-opening DB connections.

Your overall architecture may be questioned, however: polling for updates on a timer is usually not the best option. A better approach would be maintaining an update sequence in a separate table. The table would have a single row, with a single int column initially set to zero. Every time an update to the "real" data is made, this number is bumped up by one. With this table in place, your program could read just this one number every second, rather than re-reading your entire data set. If your program detects that the number is the same as it was the previous time, it stops and waits for the next timer interval; otherwise, it re-reads the data set.

Upvotes: 1

Related Questions