I thought one of the points about async/await is that when the task completes, the continuation is run on the same context when the await was called, which would, in my case, be the UI thread.
So for example:
Debug.WriteLine("2: Thread ID: " + Thread.CurrentThread.ManagedThreadId);
await fs.ReadAsync(data, 0, (int)fs.Length);
Debug.WriteLine("3: Thread ID: " + Thread.CurrentThread.ManagedThreadId);
I would NOT expect this:
2: Thread ID: 10
3: Thread ID: 11
What gives? Why is the thread ID for the continuation different than the UI thread?
According to this article[^] I would need to explicitly call ConfigureAwait to change the behavior of the continuation context!
ConfigureAwait(false)
anywhere before this fragment? Or perhaps this code fragment is used inside an async lambda like this:await Task.Run(async () => { /* no synchronization context here! */ })
? – noseratio