Scheduling context and threads in connection to async/await

Hi!

I have been reading about async and await, and I get most of it. But there is one thing I don't get: scheduling contexts. I have a few questions (that may overlap a lot):

What is a scheduling context?

What is a SynchronizationContext?

Does running in the same scheduling context or SynchronizationContext actually mean running on the same thread? I've heard that UI stuff must happen on the UI thread, but how can a continuation (after await) run on the UI thread if the UI thread never stops/yields? What if the UI thread is running in a loop doing work? Just now it ocurred to me that it probably does pause/yield, or whatever, a lot, but say if it didn't, or that another thread fires off a lot of awaits, and then never stops working.

What if I call lots and lots of async methods, say if I'm writing a web crawler and I want to do 100 web requests per second. What will happen to all those continuations if they all want to resume in the same context, and the original thread never stops to let anything else run on it?

I have heard that one can use ConfigureAwait(continueOnCapturedContext: false), but when/where is that safe? What context are we talking about here?

by tufflax via /r/csharp

Leave a Reply