You need to replace the comment //Do Something
with some code that actually does something on another thread. If you don't, you will never get the chance to see the "Status: Not ready" message as the Text
property will be set to "Status: Ready" almost immediately after you have clicked the Button
.
Try this:
private async void Button_Click(object sender, RoutedEventArgs e)
{
myTextBlock.Text = "Status: Not ready";
await Task.Delay(3000); //wait asynchronously for 3 seconds..
myTextBlock.Text = "Status: Ready";
}
After you have confirmed that this works as expected you probably want to start a task that does something meaningful as suggested by @Fruchtzwerg. ConfigureAwait(true)
is superfluous here though:
await Task.Run(() =>
{
//Do something
});