In an attempt to understand async/await I made a little sample WPF application that has one button. When clicked it will do some 'work' :
private async void goButtonClicked(object sender, EventArgs e)
{
WhatThreadAmI();
var task = populateRawData().ConfigureAwait(false);
WhatThreadAmI();
BusyIndicator.IsBusy = true;
await task;
WhatThreadAmI(); //this isnt on the main thread - why??
BusyIndicator.IsBusy = false;
Console.WriteLine("fin");
}
The "WhatThreadAmI" simply compares the current thread to the UI thread which I save on initialization.
public bool IsMainThread => uiThread == Thread.CurrentThread;
I expected the output of this to be True - True - True, with the "WhatThreadAmI" call in the populate raw data method to return false.
What actually happens is True - True - False, with the ""WhatThreadAmI" call in the populate raw data method returning true.
I know I must be missing something very fundamental here, but can someone please help me understand what is going on?