SynchronizationContext Class

SynchronizationContext Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Provides the basic functionality for propagating a synchronization context in various synchronization models.


Namespace:  System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public class SynchronizationContext

The SynchronizationContext type exposes the following members.

Public methodSynchronizationContextCreates a new instance of the SynchronizationContext class.

Public propertyStatic memberCurrentGets the synchronization context for the current thread.

Public methodCreateCopyWhen overridden in a derived class, creates a copy of the synchronization context.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodOperationCompletedWhen overridden in a derived class, responds to the notification that an operation has completed.
Public methodOperationStartedWhen overridden in a derived class, responds to the notification that an operation has started.
Public methodPostWhen overridden in a derived class, dispatches an asynchronous message to a synchronization context.
Public methodSendWhen overridden in a derived class, dispatches a synchronous message to a synchronization context.
Public methodStatic memberSetSynchronizationContextSecurity Critical. Sets the current synchronization context.
Public methodStatic memberSetThreadStaticContextSecurity Critical. Sets the current context for thread static data.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)

The SynchronizationContext class is a base class that provides a free-threaded context with no synchronization.

The purpose of the synchronization model implemented by this class is to allow the internal asynchronous/synchronization operations of the common language runtime to behave properly with different synchronization models. This model also simplifies some of the requirements that managed applications have had to follow in order to work correctly under different synchronization environments.

Providers of synchronization models can extend this class and provide their own implementations for these methods. 

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

© 2017 Microsoft