SgDotNet
Singapore Professional .NET User Group -For Cool Developers

Datagrid Livefeed

rated by 0 users
This post has 4 Replies | 1 Follower

Top 200 Contributor
Posts 8
Atlantean Posted: 08-12-2007 1:09 AM
Hi, have anyone found a good way to simulate a live datafeed from a DB to a data-grid? (not regarding DB performance, etc, etc)
Top 10 Contributor
Posts 2,284
You may want to take a look at implementing an Observer pattern, where the observer will notify (via events) the Form that displays the DataGrid to rebind with new data.

The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Top 500 Contributor
Posts 2
Is this in WinForms or WebForms?
Top 10 Contributor
Posts 2,284

amiscell:
Is this in WinForms or WebForms?

so much for the concept of dedicated forums..... :-)

The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral

Top 500 Contributor
Posts 2

Sorry, I picked this posting from the main page and didn't see that it was part of a section dedicated to WinForms.

 Anyway, to answer the question. I am not sure if your question is related to threading or getting the notifications, but I'll address both.

In terms of threading, depending on the volume of the notifications:
- If you expect low volume, you can simply transfer the task of updating the DataTable to the GUI thread
- If the expected volume is high (tens or hundreds of notifications per second), I recommend that you build a DataView on top of your table and assign the view to the grid. When creating the view, set the filter to OriginalRows. The changes to the table can then happen on the thread that receives the notifications, except it should not commit the changes. You can then have a timer on the form which periodically acceptd the changes on the table underlying the DataView (this could be happening every half second or so). Remember to lock on the table from both threads. This will deliver high performance on the GUI in case of high volumes.
- As a side note, you do not want to rebind your data each time you receive notifications as it would collapse your GUI especially on high volumes of data or even on low volumes if the amount of data in your grid is significant. Rebinding is unnecessary, so long as you do things in the right thread.

In terms of pulling the notifications, it's up to your architecture. if you are in control of the application that updates the data, the application itself could send updates tthrough a messaging system (such as JMS) while committing the updates.
If you are not in control of the application that updates the data, you could wither do some polling from the database directly from the GUI (only if the number of clients is limited), or write a server app which does the polling and broadcasts the changes to all your clients through a messaging system.

Page 1 of 1 (5 items) | RSS
Copyright SgDotNet 2004-2008
Powered by Community Server (Commercial Edition), by Telligent Systems