With Dispatcher.BeginInvoke you are still using the UI thread for LongTimeMethod() . If this is not required (i.e., it does some background processing), I would suggest using TPL to run in the background thread:
private void ButtonClick_EventHandler(object sender, RoutedEventArgs e) { Label.Visibility = Visibility.Visible; TextBox.Text = "Processing..."; Task.Factory.StartNew(() => LongTimeMethod()) .ContinueWith(t => { Dispatcher.BeginInvoke((Action)delegate() { TextBox.Text = "Done!"; }); }); }
With this method, the long method is processed in the background thread (so the user interface thread will be free to render and the application will not freeze), and you can do anything that changes the user interface (for example, updating text field text) in the Dispatcher user interface when background task completed
Steve greatrex
source share