.NET FrameworkSynchronization Contexts

Download .NET Framework for free

Remarks

A Synchronization Context is an abstraction that allows consuming to code to pass units of work to a scheduler, without requiring awareness of how the work will be scheduled.

Synchronization contexts are traditionally used to ensure that code is run on a specific thread. In WPF and Winforms applications, a SynchronizationContext representing the UI thread is provided by the presentation framework. In this way SynchronizationContext can be thought of as a producer-consumer pattern for delegates. A worker thread will produce executable code (the delegate) and queue it or consumption by the UI message loop.

The Task Parallel Library provides features for automatically capturing and using synchronization contexts.

Related Examples

Execute code on the UI thread after performing background work