class Person : INotifyPropertyChanged { private string _name; public void Run() { //do something long... Name = "karoly"; } public string Name { get { return _name; } set { _name = value; OnPropertyChanged("Name"); } } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }
Person person; public MainWindow() { InitializeComponent(); person= new Person(); this.DataContext = person; person.Name = "unknown"; } private async void RunButton_Click(object sender, RoutedEventArgs e) { Task t = new Task(person.Run); t.Start(); await t; }
Quote:Accessing collections on non-UI Threads WPF enables you to access and modify data collections on threads other than the one that created the collection. This enables you to use a background thread to receive data from an external source, such as a database, and display the data on the UI thread. By using another thread to modify the collection, your user interface remains responsive to user interaction.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)