none
Does UI databinding provide thread-safety? RRS feed

  • Question

  • Hopefully this is a simple yes/no question...

    I have a form with a number of databound user controls on it.  The datatable that they are bound to can be modified by the user's input and also by a helper object that works on a threadpool thread.

    Are these databound controls suceptible to race conditions (or other threading problems) caused by both the user and the helper modifying the data simultaneously?  If so, how would I databind in a thread-safe manner?

    Thanks for any clarifications!
    • Edited by S Wolfe Thursday, March 5, 2009 9:07 PM Shortened title
    Thursday, March 5, 2009 9:04 PM

Answers

  • Not if the data source is a DataSet/DataTable/DataView.  In all three cases, the underlying binding happens to a DataView object.  The DataView is documented "This type is safe for multithreaded read operations. You must synchronize any write operations."  You describe a case where two threads are writing to the data, so this rules out the multithreaded read special case.

    What about other scenarios?  This might be a gray area, but my advice is to not mix multithreading and data binding.

    • Marked as answer by Zhi-Xin Ye Thursday, March 12, 2009 3:44 AM
    Thursday, March 5, 2009 11:33 PM