DataSource Property and Thread Safety

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What happens if the object referenced by the DataSource property in a ListBox
is updated by another thread? Is ListBox smart enough to check InvokeRequired
before updating the GUI based on the change? IList doesn't publish any
events, so it's not clear how the changes to the IList are being detected
under the covers.
 
Even if the listbox wanted to make that check, it wouldn't matter because
the bindingmanager is not threadsafe. As documented in the ms docs, the
bindingmanagerbase class' instance methods are not thread safe. Basically,
you should not manipulate the underlying datasource from any thread but the
ui thread. The other option is to manipulate a different object that will
serve as a datasource and when you are done manipulating that, marshall a
call to the ui thread and then set the databound objects to use the new
object as its datasource.
 
Back
Top