ExecutionContext
is a state bag that captures and stores ambient state (near-by variables, other data) from the current thread and offers a way to run delegates with a specific stored ExecutionContext
as the ambient state, even if we're on a different thread.
When using ExecutionContext
, we're capturing the ambient state from the invoking thread and then restoring that state on the other thread when it's invoking a task completion or some other delegate
SynchronizationContext
is just an abstraction over a method of invoking delegates that's specific to a given environment (like Control.BeginInvoke()
for WPF or Dispatcher.BeginInvoke()
for winforms)
ex: Both WPF and windows forms offer a custom SynchronizationContext
that invokes delegates on the UI Thread, so instead of using the API thats specific to that environment, we use the abstraction (SynchronizationContext
) to make our components framework-agnosti