System.Runtime.Remoting.Contexts.SynchronizationAttribute Class

Assembly: Mscorlib.dll
Namespace: System.Runtime.Remoting.Contexts
Summary
Enforces a synchronization domain for the current context and all contexts that share the same instance.
C# Syntax:
[AttributeUsage(AttributeTargets.Class)]
[Serializable]
public class SynchronizationAttribute : ContextAttribute
Remarks
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.

Note There are two classes named SynchronizationAttribute: one in the System.Runtime.Remoting.Contexts namespace, and the other in the System.EnterpriseServices namespace. The SynchronizationAttribute class supports only synchronous calls, and can be used only with serviced components. (For more information on serviced components, see the conceptual topic at MSDN: servicedcomponentoverview.) The 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.)
Example
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 SampleSyncronized : 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("SampleSyncronized.Square is: {0}", 
                             Thread.CurrentThread.GetHashCode());
        return i*i;
    }
}

    
See also:
System.Runtime.Remoting.Contexts Namespace

System.Runtime.Remoting.Contexts.SynchronizationAttribute Member List:

Public Constructors
ctor #1 Overloaded:
.ctor()

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
Initializes a new instance of the SynchronizationAttribute class with default values.
ctor #2 Overloaded:
.ctor(bool reEntrant)

Initializes a new instance of the SynchronizationAttribute class with a Boolean value indicating whether reentry is required.
ctor #3 Overloaded:
.ctor(int flag)

Initializes a new instance of the SynchronizationAttribute class with a flag indicating the behavior of the object to which this attribute is applied.
ctor #4 Overloaded:
.ctor(int flag, bool reEntrant)

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.
Public Fields
NOT_SUPPORTED Indicates that the class to which this attribute is applied cannot be created in a context that has synchronization. This field is constant.
REQUIRED Indicates that the class to which this attribute is applied must be created in a context that has synchronization. This field is constant.
REQUIRES_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.
SUPPORTED Indicates that the class to which this attribute is applied is not dependent on whether the context has synchronization. This field is constant.
Public Properties
IsReEntrant Read-only

Gets or sets a Boolean value indicating whether reentry is required.
Locked Read-write

Gets or sets a Boolean value indicating whether the Context implementing this instance of SynchronizationAttribute is locked.
Name  (inherited) Read-only

See base class member description: System.Runtime.Remoting.Contexts.IContextProperty.Name


Gets the name of the property under which it will be added to the context.
TypeId
(inherited from System.Attribute)
Read-only

See base class member description: System.Attribute.TypeId


When implemented in a derived class, gets a unique identifier for this Attribute.
Public Methods
Equals
(inherited from System.Object)
See base class member description: System.Object.Equals

Derived from System.Object, the primary base class for all objects.
Freeze  (inherited) See base class member description: System.Runtime.Remoting.Contexts.IContextProperty.Freeze


Called when the context is frozen.
GetClientContextSink 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.
GetHashCode
(inherited from System.Attribute)
See base class member description: System.Attribute.GetHashCode


Returns the hash code for this instance.
GetPropertiesForNewContext Overridden:
Adds the Synchronized context property to the specified IConstructionCallMessage.
GetServerContextSink 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.
GetType
(inherited from System.Object)
See base class member description: System.Object.GetType

Derived from System.Object, the primary base class for all objects.
IsContextOK Overridden:
Returns a Boolean value indicating whether the context parameter meets the context attribute's requirements.
IsDefaultAttribute
(inherited from System.Attribute)
See base class member description: System.Attribute.IsDefaultAttribute


When overridden in a derived class, returns an indication whether the value of this instance is the default value for the derived class.
IsNewContextOK  (inherited) See base class member description: System.Runtime.Remoting.Contexts.IContextProperty.IsNewContextOK


Returns a Boolean value indicating whether the context property is OK with the new context.
Match
(inherited from System.Attribute)
See base class member description: System.Attribute.Match


When overridden in a derived class, returns a value indicating whether this instance equals a specified object.
ToString
(inherited from System.Object)
See base class member description: System.Object.ToString

Derived from System.Object, the primary base class for all objects.
Protected Fields
AttributeName  (inherited) This member is inherited from a type or implements a member of an interface which internally supports the .NET Framework infrastructure and is not intended to be used directly from your code.
Protected Methods
Finalize
(inherited from System.Object)
See base class member description: System.Object.Finalize

Derived from System.Object, the primary base class for all objects.
MemberwiseClone
(inherited from System.Object)
See base class member description: System.Object.MemberwiseClone

Derived from System.Object, the primary base class for all objects.

Hierarchy:


System.Runtime.Remoting.Contexts.SynchronizationAttribute Member Details

Overloaded ctor #1
Summary
Initializes a new instance of the SynchronizationAttribute class with default values.

Default constructor. This constructor is called by derived class constructors to initialize state in this type.
C# Syntax:
public SynchronizationAttribute();

Return to top


Overloaded ctor #2
Summary
Initializes a new instance of the SynchronizationAttribute class with a Boolean value indicating whether reentry is required.
C# Syntax:
public SynchronizationAttribute(
   bool reEntrant
);
Parameters:

reEntrant

A Boolean value indicating whether reentry is required.

Remarks
If reentry is required, callouts out of the Context to which the current attribute is applied must be intercepted and serialized.

Return to top


Overloaded ctor #3
Summary
Initializes a new instance of the SynchronizationAttribute class with a flag indicating the behavior of the object to which this attribute is applied.
C# Syntax:
public SynchronizationAttribute(
   int flag
);
Parameters:

flag

An integer value indicating the behavior of the object to which this attribute is applied.

Exceptions
Exception Type Condition
ArgumentException The flag parameter was not one of the defined flags.
Remarks
The flag parameter must be either SynchronizationAttribute.NOT_SUPPORTED, SynchronizationAttribute.SUPPORTED, SynchronizationAttribute.REQUIRED, or SynchronizationAttribute.REQUIRES_NEW.

Return to top


Overloaded ctor #4
Summary
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.
C# Syntax:
public SynchronizationAttribute(
   int flag,
   bool reEntrant
);
Parameters:

flag

An integer value indicating the behavior of the object to which this attribute is applied.

reEntrant

true if reentry is required, and callouts must be intercepted and serialized; otherwise, false.

Exceptions
Exception Type Condition
ArgumentException The flag parameter was not one of the defined flags.
Remarks
The flag parameter must be either SynchronizationAttribute.NOT_SUPPORTED, SynchronizationAttribute.SUPPORTED, SynchronizationAttribute.REQUIRED, or SynchronizationAttribute.REQUIRES_NEW.

Return to top


Field: AttributeName
Inherited
This member is inherited from a type or implements a member of an interface which internally supports the .NET Framework infrastructure and is not intended to be used directly from your code.

Return to top


Field: NOT_SUPPORTED
Summary
Indicates that the class to which this attribute is applied cannot be created in a context that has synchronization. This field is constant.
C# Syntax:
public const int NOT_SUPPORTED;

Return to top


Field: REQUIRED
Summary
Indicates that the class to which this attribute is applied must be created in a context that has synchronization. This field is constant.
C# Syntax:
public const int REQUIRED;

Return to top


Field: REQUIRES_NEW
Summary
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.
C# Syntax:
public const int REQUIRES_NEW;

Return to top


Field: SUPPORTED
Summary
Indicates that the class to which this attribute is applied is not dependent on whether the context has synchronization. This field is constant.
C# Syntax:
public const int SUPPORTED;

Return to top


Property: IsReEntrant (read-only)
Summary
Gets or sets a Boolean value indicating whether reentry is required.
C# Syntax:
public virtual bool IsReEntrant {get;}
Remarks
If reentry is required, callouts out of the Context to which the current attribute is applied must be intercepted and serialized.

Return to top


Property: Locked (read-write)
Summary
Gets or sets a Boolean value indicating whether the Context implementing this instance of SynchronizationAttribute is locked.
C# Syntax:
public virtual bool Locked {get; set;}
Remarks
When a synchronized Context is locked, only the thread currently executing in it has access to objects in the Context.

Return to top


Property: Name (read-only)
Inherited
See base class member description: System.Runtime.Remoting.Contexts.IContextProperty.Name

Summary
Gets the name of the property under which it will be added to the context.
C# Syntax:
string Name {get;}

Return to top


Property: TypeId (read-only)
Inherited
See base class member description: System.Attribute.TypeId

Summary
When implemented in a derived class, gets a unique identifier for this Attribute.
C# Syntax:
public virtual object TypeId {get;}
Remarks
As implemented, this identifier is merely the Type of the attribute. However, it is intended that the unique identifier be used to identify two attributes of the same type.

Return to top


Method: Equals(
   object o
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object o
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~SynchronizationAttribute();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Freeze(
   Context newContext
)
Inherited
See base class member description: System.Runtime.Remoting.Contexts.IContextProperty.Freeze

Summary
Called when the context is frozen.
C# Syntax:
void Freeze(
   Context newContext
);
Parameters:

newContext

The context to freeze.

Remarks
Context properties cannot be added after the context has been frozen.

Return to top


Method: GetClientContextSink(
   IMessageSink nextSink
)
Summary
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.
C# Syntax:
public virtual IMessageSink GetClientContextSink(
   IMessageSink nextSink
);
Parameters:

nextSink

The chain of sinks composed so far.

Return Value:
The composite sink chain with the new CallOut sink.
Implements:
IContributeClientContextSink.GetClientContextSink
Remarks
The current method is an implementation of IContributeClientContextSink.GetClientContextSink.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Attribute.GetHashCode

Summary
Returns the hash code for this instance.
C# Syntax:
public override int GetHashCode();
Return Value:
A 32-bit signed integer hash code.

Return to top


Overridden Method: GetPropertiesForNewContext(
   IConstructionCallMessage ctorMsg
)
Summary
Adds the Synchronized context property to the specified IConstructionCallMessage.
C# Syntax:
public override void GetPropertiesForNewContext(
   IConstructionCallMessage ctorMsg
);
Parameters:

ctorMsg

The IConstructionCallMessage to which to add the property.

Implements:
IContextAttribute.GetPropertiesForNewContext

Return to top


Method: GetServerContextSink(
   IMessageSink nextSink
)
Summary
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.
C# Syntax:
public virtual IMessageSink GetServerContextSink(
   IMessageSink nextSink
);
Parameters:

nextSink

The chain of sinks composed so far.

Return Value:
The composite sink chain with the new synchronized dispatch sink.
Implements:
IContributeServerContextSink.GetServerContextSink
Remarks
The current method is an implementation of IContributeServerContextSink.GetServerContextSink.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Overridden Method: IsContextOK(
   Context ctx,
   IConstructionCallMessage msg
)
Summary
Returns a Boolean value indicating whether the context parameter meets the context attribute's requirements.
C# Syntax:
public override bool IsContextOK(
   Context ctx,
   IConstructionCallMessage msg
);
Parameters:

ctx

The context to check. The context to check.

msg

Information gathered at construction time of the context bound object marked by this attribute. The SynchronizationAttribute can inspect, add to, and remove properties from the context while determining if the context is acceptable to it.

Return Value:
true if the passed in context is OK; otherwise, false.
Exceptions
Exception Type Condition
ArgumentNullException The ctx or msg parameter is null.
Implements:
IContextAttribute.IsContextOK

Return to top


Method: IsDefaultAttribute()
Inherited
See base class member description: System.Attribute.IsDefaultAttribute

Summary
When overridden in a derived class, returns an indication whether the value of this instance is the default value for the derived class.
C# Syntax:
public virtual bool IsDefaultAttribute();
Return Value:
true if this instance is the default attribute for the class; otherwise, false.
Remarks
The default implementation of this class returns false, and must be implemented in the derived class to be useful to that class.

The implementation of this method in a derived class compares the value of this instance to a standard, default value obtained by some means, then returns a Boolean value that indicates whether the value of this instance is equal to the standard. The standard value is typically coded as a constant in the implementation, or stored programmatically in a field used by the implementation.

Return to top


Method: IsNewContextOK(
   Context newCtx
)
Inherited
See base class member description: System.Runtime.Remoting.Contexts.IContextProperty.IsNewContextOK

Summary
Returns a Boolean value indicating whether the context property is OK with the new context.
C# Syntax:
bool IsNewContextOK(
   Context newCtx
);
Parameters:

newCtx

The new Context in which the ContextProperty has been created.

Return Value:
true if the context property can coexist with the other context properties in the given context; false otherwise.
Remarks
Once all the context properties have been added to the new context, they are all asked whether they are OK in the new context. The context property could look at the other context properties from the parameter new context and determine whether it is compatible with these other context properties. Returns false if not OK in the context.

Return to top


Method: Match(
   object obj
)
Inherited
See base class member description: System.Attribute.Match

Summary
When overridden in a derived class, returns a value indicating whether this instance equals a specified object.
C# Syntax:
public virtual bool Match(
   object obj
);
Parameters:

obj

An Object to compare with this instance of Attribute.

Return Value:
true if this instance equals obj; otherwise, false.
Remarks
This method determines if one Attribute equals another. Its default implementation is the same as Attribute.Equals, which performs a value and reference comparison. Override this method to implement support for attribute values, such as flags or bitfields, that consist of components that are meaningful in themselves. For example, consider an attribute whose value is a binary field divided into a bitfield of flags. Two instances of this attribute have one flag in set in common while all the other flags differ. The Equal method cannot determine that the two instances have the same flag set, but the Match method can.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.