SynchronizationAttribute SynchronizationAttribute SynchronizationAttribute SynchronizationAttribute Class

定義

對目前內容和共用相同執行個體的所有內容強制使用同步網域。Enforces a synchronization domain for the current context and all contexts that share the same instance.

public ref class SynchronizationAttribute : System::Runtime::Remoting::Contexts::ContextAttribute, System::Runtime::Remoting::Contexts::IContributeClientContextSink, System::Runtime::Remoting::Contexts::IContributeServerContextSink
[System.AttributeUsage(System.AttributeTargets.Class)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
[System.Serializable]
public class SynchronizationAttribute : System.Runtime.Remoting.Contexts.ContextAttribute, System.Runtime.Remoting.Contexts.IContributeClientContextSink, System.Runtime.Remoting.Contexts.IContributeServerContextSink
type SynchronizationAttribute = class
    inherit ContextAttribute
    interface IContributeClientContextSink
    interface IContributeServerContextSink
Public Class SynchronizationAttribute
Inherits ContextAttribute
Implements IContributeClientContextSink, IContributeServerContextSink
繼承
SynchronizationAttributeSynchronizationAttributeSynchronizationAttributeSynchronizationAttribute
屬性
實作

範例

下列程式碼範例示範的用法SynchronizationAttributeThe following code example demonstrates the use of the SynchronizationAttribute. 如需完整的範例程式碼, 請參閱AsyncResult類別的範例。For the complete example code, see the example for the AsyncResult class.

// Context-bound type with the Synchronization context attribute.

[Synchronization]
public ref class SampleSynchronized: public ContextBoundObject
{
public:

   // A method that does some work, and returns the square of the given number.
   int Square( int i )
   {
      Console::Write( "The hash of the thread executing " );
      Console::WriteLine( "SampleSynchronized::Square is: {0}", Thread::CurrentThread->GetHashCode() );
      return i * i;
   }

};
// 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;
    }
}
' Context-bound type with the Synchronization context attribute.
<Synchronization()> Public Class SampleSynchronized
   Inherits ContextBoundObject
   
   ' A method that does some work, and returns the square of the given number.
   Public Function Square(i As Integer) As Integer
      
      Console.Write("The hash of the thread executing ")
      Console.WriteLine("SampleSynchronized.Square is: {0}", Thread.CurrentThread.GetHashCode())
      Return i * i
   End Function 

End Class 

備註

當此屬性套用至物件時, 只有一個執行緒可以在共用這個屬性之實例的所有內容中執行。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.

注意

有兩個名為SynchronizationAttributeSystem.Runtime.Remoting.Contexts類別: 一個在命名空間中, 另一個System.EnterpriseServices在命名空間中。There are two classes named SynchronizationAttribute : one in the System.Runtime.Remoting.Contexts namespace, and the other in the System.EnterpriseServices namespace. System.EnterpriseServices.SynchronizationAttribute類別僅支援同步呼叫, 而且只能與已服務的元件搭配使用。The System.EnterpriseServices.SynchronizationAttribute class supports only synchronous calls, and can be used only with serviced components. 同時System.Runtime.Remoting.Contexts.SynchronizationAttribute支援同步和非同步呼叫, 而且只能與內容系結物件搭配使用。The System.Runtime.Remoting.Contexts.SynchronizationAttribute supports both synchronous and asynchronous calls, and can be used only with context bound objects. (如需內容系結物件的詳細資訊, ContextBoundObject請參閱類別)。(For more information on context bound objects, see the ContextBoundObject class.)

注意

這個類別會在類別層級建立連結要求和繼承要求。This class makes a link demand and an inheritance demand at the class level. 當立即呼叫端或衍生類別沒有基礎結構許可權時,就會擲回。SecurityExceptionA 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.

建構函式

SynchronizationAttribute() SynchronizationAttribute() SynchronizationAttribute() SynchronizationAttribute()

使用預設值,初始化 SynchronizationAttribute 類別的新執行個體。Initializes a new instance of the SynchronizationAttribute class with default values.

SynchronizationAttribute(Boolean) SynchronizationAttribute(Boolean) SynchronizationAttribute(Boolean) SynchronizationAttribute(Boolean)

使用指示是否需要重新進入的布林 (Boolean) 值,初始化 SynchronizationAttribute 類別的新執行個體。Initializes a new instance of the SynchronizationAttribute class with a Boolean value indicating whether reentry is required.

SynchronizationAttribute(Int32) SynchronizationAttribute(Int32) SynchronizationAttribute(Int32) SynchronizationAttribute(Int32)

使用指示套用這個屬性的物件之行為的旗標,初始化 SynchronizationAttribute 類別的新執行個體。Initializes a new instance of the SynchronizationAttribute class with a flag indicating the behavior of the object to which this attribute is applied.

SynchronizationAttribute(Int32, Boolean) SynchronizationAttribute(Int32, Boolean) SynchronizationAttribute(Int32, Boolean) SynchronizationAttribute(Int32, Boolean)

使用指示套用這個屬性的物件之行為的旗標,和指示是否需要重新進入的布林值,初始化 SynchronizationAttribute 類別的新執行個體。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.

欄位

AttributeName AttributeName AttributeName AttributeName

表示內容屬性的名稱。Indicates the name of the context attribute.

(Inherited from ContextAttribute)
NOT_SUPPORTED NOT_SUPPORTED NOT_SUPPORTED 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 REQUIRED REQUIRED 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 REQUIRES_NEW REQUIRES_NEW 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 SUPPORTED SUPPORTED SUPPORTED

指示套用這個屬性的類別與內容是否有同步處理無關。Indicates that the class to which this attribute is applied is not dependent on whether the context has synchronization. 這個欄位是常數。This field is constant.

屬性

IsReEntrant IsReEntrant IsReEntrant IsReEntrant

取得或設定布林值,指出是否需要重新進入。Gets or sets a Boolean value indicating whether reentry is required.

Locked Locked Locked Locked

取得或設定布林值,指出是否鎖定 Context (實作 SynchronizationAttribute 的這個執行個體)。Gets or sets a Boolean value indicating whether the Context implementing this instance of SynchronizationAttribute is locked.

Name Name Name Name

取得內容屬性的名稱。Gets the name of the context attribute.

(Inherited from ContextAttribute)
TypeId TypeId TypeId TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

傳回布林 (Boolean) 值,指出這個執行個體是否等於指定的物件。Returns a Boolean value indicating whether this instance is equal to the specified object.

(Inherited from ContextAttribute)
Freeze(Context) Freeze(Context) Freeze(Context) Freeze(Context)

在內容已凍結時呼叫。Called when the context is frozen.

(Inherited from ContextAttribute)
GetClientContextSink(IMessageSink) GetClientContextSink(IMessageSink) GetClientContextSink(IMessageSink) GetClientContextSink(IMessageSink)

建立 CallOut 接收,並且在提供的接收 (在遠端呼叫用戶端上的內容界限) 的鏈結前面來鏈結它。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() GetHashCode() GetHashCode() GetHashCode()

傳回 ContextAttribute 的這個執行個體的雜湊程式碼。Returns the hashcode for this instance of ContextAttribute.

(Inherited from ContextAttribute)
GetPropertiesForNewContext(IConstructionCallMessage) GetPropertiesForNewContext(IConstructionCallMessage) GetPropertiesForNewContext(IConstructionCallMessage) GetPropertiesForNewContext(IConstructionCallMessage)

加入 Synchronized 的內容屬性至指定的 IConstructionCallMessageAdds the Synchronized context property to the specified IConstructionCallMessage.

GetServerContextSink(IMessageSink) GetServerContextSink(IMessageSink) GetServerContextSink(IMessageSink) GetServerContextSink(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.

GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IsContextOK(Context, IConstructionCallMessage) IsContextOK(Context, IConstructionCallMessage) IsContextOK(Context, IConstructionCallMessage) IsContextOK(Context, IConstructionCallMessage)

傳回布林值,指出是否內容參數符合內容屬性的需求。Returns a Boolean value indicating whether the context parameter meets the context attribute's requirements.

IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
IsNewContextOK(Context) IsNewContextOK(Context) IsNewContextOK(Context) IsNewContextOK(Context)

傳回布林值,指出內容屬性是否與新內容相容。Returns a Boolean value indicating whether the context property is compatible with the new context.

(Inherited from ContextAttribute)
Match(Object) Match(Object) Match(Object) Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

明確介面實作

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _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)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

安全性

SecurityPermission
用於操作基礎結構程式碼。for operating with infrastructure code. 需求值: InheritanceDemand;許可權值:InfrastructureDemand value: InheritanceDemand; Permission Value: Infrastructure

適用於