Hi,
I'm currently designing/reworking the databinding part of an application that makes heavy use of winforms databinding and updates coming from a background thread (once a second on > 100 records). Let's assume the application is a stock trading application, where a background thread monitors for data changes and putting them onto the data objects. These objects are stored in a bindinglist<> and implement INotifyPropertyChanged to propagate the changes via databinding to the winforms controls. Additionally the data objects are currently marshalling the changes via WinformsSynchronizationContext.Send to the UI thread. The user is able to enter some of the values in the UI, which means that some values can be changed from both sides. And the user values shouldn't be overritten by updates.
So there are several question coming to my mind:
- Is there a general design-guildline how to do that (background updates in databinding)?
- When and how to marshal on the UI thread?
- What is the best way of the background thread to interact with binding/data objects?
- Which classes/Interfaces should be used? (BindingSource, ...)
- ...
I'm search for general proposals/design guidelines for such scenarios...
I'm thankful for all ideas, links, ...
tia Martin
thx for the ideas so far, but I'm know Control.Invoke/BeginInvoke,... I'm more interessted in best practice. As an additional info, the UI doesn't really know that there is a background thread, that updates the control, and as of my understanding in databinding scenarios the UI shouldn't know where the data is coming from... You can think of the background thread as something that pushes data to the UI, so I'm not sure if the backgroundworker is the option I'm searching for.
Edit: Another question came to my mind: Something you want to get some UI response during an operation in the data-/business object (e.g. setting the background during recalculations). Raising a propertychanged on a status property which is bound to the background isn't enough, as the control get's repainted after the calculation has finished? My idea would be to hook on the propertychanged event and call .update() on the control... Any other ideas about that?