For example, I have a business object Person:
class Person : INotifyPropertyChanged
{
string Name { get; set; }
DateTime DateOfBirth { get; set; }
}
And I have some Winforms UI that manages data bound to an object of this class:
Person somePerson = ...;
nameTextBox.DataBindings.Add("Text", somePerson, "Name");
dobDatePicker.DataBindings.Add("Value", somePerson, "DateOfBirth");
Now I am making changes to somePersonand thanks to the implementation, INotifyPropertyChangedthese changes are reflected in the user interface. So far so good.
Now to my problem: If I make changes to somePersonthe workflow (i.e. not the user interface thread), for example. because I am loading data from the database as a background operation, this can throw exceptions because data binding is trying to update controls, which is only allowed in the user interface thread.
, InvokeRequired , , - — .
-, , . Winforms ?