Interview Question

What is SynchronizationContext?

SynchronizationContext represents an environment for scheduling callbacks.

💡 Concept ✅ Quick Revision 🔷 C#

Answer

SynchronizationContext is an abstraction for posting and sending work to an execution environment. • UI frameworks can use it to marshal continuations back to a UI thread. • An await may capture the current context unless configured otherwise. • Console and server applications may have no custom synchronization context.

💡 C# Example

SynchronizationContext? context = SynchronizationContext.Current; Console.WriteLine(context?.GetType().Name ?? "No custom context");

Output

Context type or No custom context

⚡ Quick Revision

SynchronizationContext represents an environment for scheduling callbacks.