views:

128

answers:

2

I need advice and clarification please. I'm currently working on a monitor app that needs to show the contents of a database in a datagrid (I'm using the WPFToolkit grid btw). The grid binds to a table in my ADO.NET DataSet and it works fine. If I modify the DataSet through a button in my UI the grid updates and everyone is happy (binding and ADO.NET is nicely described in this blog). However, the database will be updates by other applications and the monitor app needs to display those changes automatically. The DataSet is updated through polling the database (for various reasons listening to post_events from the DB is not applicable) but the changes are not displayed in the grid.

As far as I have understood this is a feature of WPF databinding. You cannot update the source from another thread than the UI's. In my mind this is insane. There must be thousands of apps out there where data is entered from another user or application. I have tried using the Dispatcher to move the actual updating of the source to the UI thread but I still get the same error.

So now to my question: Is my analysis correct and if so can you offer any advice on how to solve the problem? Also if my analysis is correct can someone please try to explain why WPF works like that?

Thank you for your time

A: 

Probably! not the solution to your problem but have a look here http://weblogs.asp.net/cschittko/archive/2008/05/14/wpf-ui-update-from-background-threads.aspx, it might give you some more avenues to look at.

Another link is here http://stackoverflow.com/questions/1098929/wpf-update-multiple-controls-via-dispatcher

HTH

Anand
A: 

After doing even more research I have found my analysis to be correct. While I haven't figured out a way to make it work within ADO.NET I did find a good solution here that uses a simple derivate of ObservableCollection.

Using the RowChanged event from the DataTable I keep track of a BindableCollection view of the table and use that as my DataContext. Works like a charm.

Farawin