SynchronizationAttribute 類別

定義

對目前內容和共用相同執行個體的所有內容強制使用同步網域。

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.Serializable]
public class SynchronizationAttribute : System.Runtime.Remoting.Contexts.ContextAttribute, System.Runtime.Remoting.Contexts.IContributeClientContextSink, System.Runtime.Remoting.Contexts.IContributeServerContextSink
[System.AttributeUsage(System.AttributeTargets.Class)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class SynchronizationAttribute : System.Runtime.Remoting.Contexts.ContextAttribute, System.Runtime.Remoting.Contexts.IContributeClientContextSink, System.Runtime.Remoting.Contexts.IContributeServerContextSink
[System.AttributeUsage(System.AttributeTargets.Class)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Security.SecurityCritical]
public class SynchronizationAttribute : System.Runtime.Remoting.Contexts.ContextAttribute, System.Runtime.Remoting.Contexts.IContributeClientContextSink, System.Runtime.Remoting.Contexts.IContributeServerContextSink
[<System.AttributeUsage(System.AttributeTargets.Class)>]
[<System.Serializable>]
type SynchronizationAttribute = class
    inherit ContextAttribute
    interface IContributeServerContextSink
    interface IContributeClientContextSink
[<System.AttributeUsage(System.AttributeTargets.Class)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SynchronizationAttribute = class
    inherit ContextAttribute
    interface IContributeServerContextSink
    interface IContributeClientContextSink
[<System.AttributeUsage(System.AttributeTargets.Class)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Security.SecurityCritical>]
type SynchronizationAttribute = class
    inherit ContextAttribute
    interface IContributeServerContextSink
    interface IContributeClientContextSink
[<System.AttributeUsage(System.AttributeTargets.Class)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SynchronizationAttribute = class
    inherit ContextAttribute
    interface IContributeClientContextSink
    interface IContributeServerContextSink
Public Class SynchronizationAttribute
Inherits ContextAttribute
Implements IContributeClientContextSink, IContributeServerContextSink
繼承
SynchronizationAttribute
屬性
實作

範例

下列程式碼範例示範 如何使用 SynchronizationAttribute 。 如需完整的範例程式碼,請參閱 類別的 AsyncResult 範例。

// 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

備註

當這個屬性套用至物件時,只有一個執行緒可以在共用此屬性實例的所有內容中執行。 這是藉由參與接收來攔截和序列化個別內容的撥入電話來完成。 如果屬性標示為重新輸入,則圖說文字也會被攔截。 圖說文字攔截可讓其他等候執行緒進入同步處理網域,以達到最大輸送量。

注意

命名空間中有兩個名為 的 SynchronizationAttribute 類別:一個在 System.Runtime.Remoting.Contexts 命名空間中,另一個類別則位於 命名空間中 System.EnterpriseServices 。 類別 System.EnterpriseServices.SynchronizationAttribute 僅支援同步呼叫,而且只能與服務元件搭配使用。 System.Runtime.Remoting.Contexts.SynchronizationAttribute同時支援同步和非同步呼叫,而且只能與內容系結物件搭配使用。 (如需內容系結物件的詳細資訊,請參閱 ContextBoundObject class.)

注意

這個類別會在類別層級建立連結需求和繼承需求。 SecurityException當立即呼叫端或衍生類別沒有基礎結構許可權時,就會擲回 。 如需安全性需求的詳細資訊,請參閱 連結需求繼承需求

建構函式

SynchronizationAttribute()

使用預設值,初始化 SynchronizationAttribute 類別的新執行個體。

SynchronizationAttribute(Boolean)

使用指示是否需要重新進入的布林 (Boolean) 值,初始化 SynchronizationAttribute 類別的新執行個體。

SynchronizationAttribute(Int32)

使用指示套用這個屬性的物件之行為的旗標,初始化 SynchronizationAttribute 類別的新執行個體。

SynchronizationAttribute(Int32, Boolean)

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

欄位

AttributeName

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

表示內容屬性的名稱。

(繼承來源 ContextAttribute)
NOT_SUPPORTED

指示套用這個屬性的類別無法在具有同步處理的內容中建立。 這個欄位為常數。

REQUIRED

指示套用這個屬性的類別必須在具有同步處理的內容中建立。 這個欄位為常數。

REQUIRES_NEW

指示套用這個屬性的類別每一次都必須在內容中以同步處理屬性的新執行個體來建立。 這個欄位為常數。

SUPPORTED

指示套用這個屬性的類別與內容是否有同步處理無關。 這個欄位為常數。

屬性

IsReEntrant

取得或設定布林值,指出是否需要重新進入。

Locked

取得或設定布林值,指出是否鎖定 Context (實作 SynchronizationAttribute 的這個執行個體)。

Name

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

取得內容屬性的名稱。

(繼承來源 ContextAttribute)
TypeId

在衍生類別中實作時,取得這個 Attribute 的唯一識別碼。

(繼承來源 Attribute)

方法

Equals(Object)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

傳回布林 (Boolean) 值,指出這個執行個體是否等於指定的物件。

(繼承來源 ContextAttribute)
Freeze(Context)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

在內容已凍結時呼叫。

(繼承來源 ContextAttribute)
GetClientContextSink(IMessageSink)

建立 CallOut 接收,並且在提供的接收 (在遠端呼叫用戶端上的內容界限) 的鏈結前面來鏈結它。

GetHashCode()

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

傳回 ContextAttribute 的這個執行個體的雜湊程式碼。

(繼承來源 ContextAttribute)
GetPropertiesForNewContext(IConstructionCallMessage)

加入 Synchronized 的內容屬性至指定的 IConstructionCallMessage

GetServerContextSink(IMessageSink)

建立同步化分派接收,並且在提供的接收 (在遠端呼叫伺服器端上的內容界限) 的鏈結前面來鏈結它。

GetType()

取得目前執行個體的 Type

(繼承來源 Object)
IsContextOK(Context, IConstructionCallMessage)

傳回布林值,指出是否內容參數符合內容屬性的需求。

IsDefaultAttribute()

在衍生類別中覆寫時,表示這個執行個體的值是衍生類別的預設值。

(繼承來源 Attribute)
IsNewContextOK(Context)

此 API 支援此產品基礎結構,但無法直接用於程式碼之中。

傳回布林值,指出內容屬性是否與新內容相容。

(繼承來源 ContextAttribute)
Match(Object)

在衍生類別中覆寫時,會傳回值,表示這個執行個體是否等於指定物件。

(繼承來源 Attribute)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

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

將一組名稱對應至一組對應的分派識別項 (Dispatch Identifier)。

(繼承來源 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

擷取物件的類型資訊,可以用來取得介面的類型資訊。

(繼承來源 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

擷取物件提供的類型資訊介面數目 (0 或 1)。

(繼承來源 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供物件所公開的屬性和方法的存取權。

(繼承來源 Attribute)

適用於