SynchronizationAttribute Class

SynchronizationAttribute Class

 

Enforces a synchronization domain for the current context and all contexts that share the same instance.

Namespace:   System.Runtime.Remoting.Contexts
Assembly:  mscorlib (in mscorlib.dll)

System.Object
  System.Attribute
    System.Runtime.Remoting.Contexts.ContextAttribute
      System.Runtime.Remoting.Contexts.SynchronizationAttribute

[SerializableAttribute]
[SecurityCriticalAttribute]
[AttributeUsageAttribute(AttributeTargets.Class)]
[ComVisibleAttribute(true)]
[SecurityPermissionAttribute(SecurityAction.InheritanceDemand, 
	Flags = SecurityPermissionFlag.Infrastructure)]
public class SynchronizationAttribute : ContextAttribute, IContributeServerContextSink, 
	IContributeClientContextSink

NameDescription
System_CAPS_pubmethodSynchronizationAttribute()

Initializes a new instance of the SynchronizationAttribute class with default values.

System_CAPS_pubmethodSynchronizationAttribute(Boolean)

Initializes a new instance of the SynchronizationAttribute class with a Boolean value indicating whether reentry is required.

System_CAPS_pubmethodSynchronizationAttribute(Int32)

Initializes a new instance of the SynchronizationAttribute class with a flag indicating the behavior of the object to which this attribute is applied.

System_CAPS_pubmethodSynchronizationAttribute(Int32, Boolean)

Initializes a new instance of the SynchronizationAttribute class with a flag indicating the behavior of the object to which this attribute is applied, and a Boolean value indicating whether reentry is required.

NameDescription
System_CAPS_pubpropertyIsReEntrant

Gets or sets a Boolean value indicating whether reentry is required.

System_CAPS_pubpropertyLocked

Gets or sets a Boolean value indicating whether the Context implementing this instance of SynchronizationAttribute is locked.

System_CAPS_pubpropertyName

This API supports the product infrastructure and is not intended to be used directly from your code. Gets the name of the context attribute.(Inherited from ContextAttribute.)

System_CAPS_pubpropertyTypeId

When implemented in a derived class, gets a unique identifier for this Attribute.(Inherited from Attribute.)

NameDescription
System_CAPS_pubmethodEquals(Object)

This API supports the product infrastructure and is not intended to be used directly from your code. Returns a Boolean value indicating whether this instance is equal to the specified object.(Inherited from ContextAttribute.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodFreeze(Context)

This API supports the product infrastructure and is not intended to be used directly from your code. Called when the context is frozen.(Inherited from ContextAttribute.)

System_CAPS_pubmethodGetClientContextSink(IMessageSink)

Creates a CallOut sink and chains it in front of the provided chain of sinks at the context boundary on the client end of a remoting call.

System_CAPS_pubmethodGetHashCode()

This API supports the product infrastructure and is not intended to be used directly from your code. Returns the hashcode for this instance of ContextAttribute.(Inherited from ContextAttribute.)

System_CAPS_pubmethodGetPropertiesForNewContext(IConstructionCallMessage)

Adds the Synchronized context property to the specified IConstructionCallMessage.(Overrides ContextAttribute.GetPropertiesForNewContext(IConstructionCallMessage).)

System_CAPS_pubmethodGetServerContextSink(IMessageSink)

Creates a synchronized dispatch sink and chains it in front of the provided chain of sinks at the context boundary on the server end of a remoting call.

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIsContextOK(Context, IConstructionCallMessage)

Returns a Boolean value indicating whether the context parameter meets the context attribute's requirements.(Overrides ContextAttribute.IsContextOK(Context, IConstructionCallMessage).)

System_CAPS_pubmethodIsDefaultAttribute()

When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.(Inherited from Attribute.)

System_CAPS_pubmethodIsNewContextOK(Context)

This API supports the product infrastructure and is not intended to be used directly from your code. Returns a Boolean value indicating whether the context property is compatible with the new context.(Inherited from ContextAttribute.)

System_CAPS_pubmethodMatch(Object)

When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_protfieldAttributeName

This API supports the product infrastructure and is not intended to be used directly from your code. Indicates the name of the context attribute.(Inherited from ContextAttribute.)

System_CAPS_pubfieldSystem_CAPS_staticNOT_SUPPORTED

Indicates that the class to which this attribute is applied cannot be created in a context that has synchronization. This field is constant.

System_CAPS_pubfieldSystem_CAPS_staticREQUIRED

Indicates that the class to which this attribute is applied must be created in a context that has synchronization. This field is constant.

System_CAPS_pubfieldSystem_CAPS_staticREQUIRES_NEW

Indicates that the class to which this attribute is applied must be created in a context with a new instance of the synchronization property each time. This field is constant.

System_CAPS_pubfieldSystem_CAPS_staticSUPPORTED

Indicates that the class to which this attribute is applied is not dependent on whether the context has synchronization. This field is constant.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.GetTypeInfoCount(UInt32)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.)

System_CAPS_pubinterfaceSystem_CAPS_privmethod_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.(Inherited from Attribute.)

When this attribute is applied to an object, only one thread can be executing in all contexts that share an instance of this property. This is done by contributing sinks that intercept and serialize incoming calls for the respective contexts. If the property is marked for reentry, then callouts are intercepted too. The callout interception allows other waiting threads to enter the synchronization domain for maximal throughput.

System_CAPS_noteNote

There are two classes named SynchronizationAttribute : one in the System.Runtime.Remoting.Contexts namespace, and the other in the System.EnterpriseServices namespace. The System.EnterpriseServices.SynchronizationAttribute class supports only synchronous calls, and can be used only with serviced components. (For more information on serviced components, see [<topic://cpconservicedcomponentoverview>].) The System.Runtime.Remoting.Contexts.SynchronizationAttribute supports both synchronous and asynchronous calls, and can be used only with context bound objects. (For more information on context bound objects, see the ContextBoundObject class.)

System_CAPS_noteNote

This class makes a link demand and an inheritance demand at the class level. A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. For details about security demands, see Link Demands and Inheritance Demands.

The following code example demonstrates the use of the SynchronizationAttribute. For the complete example code, see the example for the AsyncResult class.

// Context-bound type with the Synchronization context attribute.
[Synchronization()]
public class SampleSynchronized : ContextBoundObject {

    // A method that does some work, and returns the square of the given number.
    public int Square(int i)  {

        Console.Write("The hash of the thread executing ");
        Console.WriteLine("SampleSynchronized.Square is: {0}", 
                             Thread.CurrentThread.GetHashCode());
        return i*i;
    }
}

SecurityPermission

for operating with infrastructure code. Demand value: SecurityAction.LinkDemand; Permission Value: SecurityPermissionFlag.Infrastructure

SecurityPermission

for operating with infrastructure code. Demand value: SecurityAction.InheritanceDemand; Permission Value: SecurityPermissionFlag.Infrastructure

.NET Framework
Available since 1.1

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

Return to top
Show:
© 2016 Microsoft