In .NET, what is the difference between SynchronizationContext and ExecutionContext?
Also explain what people mean by “context switching” in .NET. What actually happens under the hood when an async method awaits something and then resumes? Please include the role of ConfigureAwait(false), AsyncLocal<T>, and the difference between a real OS thread context switch and an async continuation switch.
Strong Candidate Answer
SynchronizationContext and ExecutionContext are two different concepts in .NET, although both are involved in asynchronous programming.
The simplest way to distinguish them is this:
SynchronizationContext answers: where should the continuation run?
ExecutionContext answers: what ambient data should flow with the continuation?
So SynchronizationContext is about scheduling and thread affinity, while ExecutionContext is about logical call context and ambient state propagation.
SynchronizationContext
SynchronizationContext represents an execution environment that knows how to schedule work back to the correct place.
The most common example is a UI application such as WPF, WinForms, or MAUI. UI controls must usually be accessed only from the UI thread. Therefore, the UI framework installs a SynchronizationContext on the UI thread.
For example:

In a UI application, this works because the await captures the current SynchronizationContext. When GetCustomerAsync() completes, the continuation is posted back to the UI thread.
Conceptually:

So SynchronizationContext is mainly about where the rest of the method should continue.
Internally, it exposes methods like:

Post means schedule asynchronously.
Send means execute synchronously on that context, if supported.
In UI frameworks, Post usually means something like:

Then the UI thread eventually picks it up and executes it.
ExecutionContext
ExecutionContext is different. It is not primarily about which thread runs the code. It is about flowing logical ambient state across asynchronous calls, thread pool work, continuations, and tasks.
It carries things like:

For example:

This prints:
REQ-123
Even if the continuation runs on another physical thread, the AsyncLocal<T> value flows.
That is the job of ExecutionContext.
A good mental model is:

But that does not mean Thread 8 permanently owns that value. The runtime temporarily restores the captured ExecutionContext while running that continuation, then restores the previous context afterward.
Conceptually:

That is simplified, but it explains the concept accurately.
A strong interview answer should say:
SynchronizationContext controls continuation scheduling. It determines whether code after an await should resume on a UI thread, a legacy ASP.NET request context, a test framework context, or some custom environment.
ExecutionContext controls logical ambient state flow. It allows values like AsyncLocal<T>, logging scopes, culture, and tracing information to flow across async boundaries even when the physical thread changes.
So:

What Happens Under the Hood with async/await?
When we write:

The compiler transforms this into a state machine. The method does not literally pause the thread. Instead, the method is split into parts.
Roughly:

The generated state machine has a MoveNext() method. The continuation is essentially a callback that invokes MoveNext() again later.
Very simplified:

The real generated code is more complex, but the main idea is:

What Context Is Captured During await?
When an await is reached, .NET considers two separate things.
First:
Where should the continuation run?
That involves SynchronizationContext and sometimes TaskScheduler.
Second:
What ambient state should flow?
That involves ExecutionContext.
So conceptually, the runtime may capture:

But they serve different purposes.
A simplified model is:

Again, this is conceptual, not the exact runtime source code.
The important point is:

ConfigureAwait(false)
ConfigureAwait(false) affects SynchronizationContext capture.
For example:

This means:

It does not normally mean:

That distinction is very important.
Example:

This still prints:
REQ-123
Because ConfigureAwait(false) avoids capturing the SynchronizationContext, but the ExecutionContext still flows.
So in an interview, I would say:
ConfigureAwait(false) tells the awaiter not to marshal the continuation back to the original SynchronizationContext or non-default scheduling context. It does not suppress ExecutionContext flow. Therefore, AsyncLocal<T>, tracing context, culture, and logging scopes usually still flow.
Consider this code:

Possible output:

This demonstrates two things:

So the physical thread may change, but the logical context remains available.
Suppressing ExecutionContext
If we really want to prevent ExecutionContext from flowing, we can use:

Example:

Output:

That is because the current ExecutionContext was not captured when the task was queued.
This should be used carefully. Suppressing ExecutionContext can improve performance in very low-level infrastructure code, but it can also break logging correlation, distributed tracing, culture propagation, tenant context, diagnostics, or security-related assumptions.
The phrase “context switching” is overloaded. In a .NET interview, I would clarify which type of context switch we are discussing.
There are several meanings.
The first is an OS thread context switch.
This is the real low-level context switch. The operating system scheduler pauses one thread and resumes another. The OS saves and restores things like CPU registers, instruction pointer, stack pointer, thread state, and scheduling information.
This can happen when a thread blocks, sleeps, waits for I/O, waits for a lock, exhausts its CPU time slice, or gets preempted by a higher-priority thread.
For example:

or:

or:

These can cause real blocking and OS scheduling activity.
The second meaning is an async continuation switch.
For example:

This may print:

But this does not necessarily mean the OS directly switched from thread 1 to thread 8 at that point.
What really happened is:

So this is a logical async continuation switch, not necessarily a direct OS context switch.
The third meaning is a SynchronizationContext switch.
This happens when a continuation is posted back to a specific context, such as the UI thread.
For example:

In a UI application:

The fourth meaning is an ExecutionContext switch.
This happens when the runtime temporarily installs a captured logical context before running a callback or continuation.
For example:

That is not primarily about changing the physical thread. It is about restoring logical ambient data.
Deadlock Scenario
A common interview follow-up is: how can SynchronizationContext cause deadlock?
Example in a UI app:

This can deadlock.
Step by step:

The core problem is:

A possible workaround is:

But the better design is usually:

So this is better:

ASP.NET Core Detail
In classic ASP.NET, there was a request-related SynchronizationContext.
In ASP.NET Core, there is generally no custom request SynchronizationContext. Usually:

So in ASP.NET Core application code, this:

and this:

usually behave similarly with respect to SynchronizationContext.
However, ExecutionContext still flows in ASP.NET Core. That is why AsyncLocal<T>, logging scopes, Activity.Current, and request correlation can flow through asynchronous code.
So in ASP.NET Core, the bigger risks are usually not missing ConfigureAwait(false), but things like:

Interview Follow-Up: TaskScheduler vs SynchronizationContext
TaskScheduler is another related concept.
SynchronizationContext is a general abstraction for posting work to a context.
TaskScheduler controls how Task work is scheduled.
When await captures context, the rough priority is:

In many server-side .NET applications:

So continuations usually run on the ThreadPool.
If I had to answer this in a concise but senior-level way, I would say:
SynchronizationContext is a scheduling abstraction. It controls where an async continuation should run. For example, in a UI application, it allows code after an await to resume on the UI thread so that UI controls can be safely accessed. It is mainly about thread affinity and continuation scheduling.
ExecutionContext is a logical context propagation mechanism. It flows ambient data such as AsyncLocal<T>, Activity.Current, logging scopes, culture, and logical call-context data across async calls, tasks, and ThreadPool work. It is not about which physical thread runs the code; it is about preserving logical state across asynchronous execution.
When an async method reaches an incomplete await, the compiler-generated state machine saves its state and registers a continuation. Depending on the await configuration, .NET may capture the current SynchronizationContext or TaskScheduler to decide where the continuation should run. Separately, it captures ExecutionContext so that ambient state can be restored when the continuation executes.
ConfigureAwait(false) tells .NET not to marshal the continuation back to the captured SynchronizationContext. It does not normally suppress ExecutionContext, so AsyncLocal<T> values and tracing context still flow.
Finally, “context switching” can mean different things. At the OS level, it means the kernel saves one thread’s CPU state and resumes another thread. In async .NET code, people often use the term more loosely to mean that a continuation resumed on a different ThreadPool thread, was posted back to a SynchronizationContext, or ran under a restored ExecutionContext. A strong engineer should distinguish those cases rather than treating them as the same thing.