通过


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
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.Runtime.Remoting.Contexts 的类在 命名空间中。 该 System.EnterpriseServices.SynchronizationAttribute 类仅支持同步调用,并且只能与服务组件一起使用。 支持 System.Runtime.Remoting.Contexts.SynchronizationAttribute 同步和异步调用,并且只能与上下文绑定对象一起使用。 (有关上下文绑定对象的详细信息,请参阅 ContextBoundObject 类。

注释

此类在类级别发出链接需求和继承需求。 当直接调用方或派生类没有基础结构权限时,将引发 A SecurityException 。 有关安全需求的详细信息,请参阅 链接需求

构造函数

名称 说明
SynchronizationAttribute()

使用默认值初始化类的新实例 SynchronizationAttribute

SynchronizationAttribute(Boolean)

使用指示是否需要重新输入的 SynchronizationAttribute 布尔值初始化类的新实例。

SynchronizationAttribute(Int32, Boolean)

使用一个标志初始化类的新实例 SynchronizationAttribute ,该标志指示应用此属性的对象的行为,以及一个指示是否需要重新输入的布尔值。

SynchronizationAttribute(Int32)

使用一个标志初始化类的新实例 SynchronizationAttribute ,该标志指示应用此属性的对象的行为。

字段

名称 说明
AttributeName

此 API 支持产品基础结构,不能在代码中直接使用。

指示上下文属性的名称。

(继承自 ContextAttribute)
NOT_SUPPORTED

指示无法在具有同步的上下文中创建应用此属性的类。 此字段为常量。

REQUIRED

指示必须在具有同步的上下文中创建应用此属性的类。 此字段为常量。

REQUIRES_NEW

指示每次必须使用同步属性的新实例在上下文中创建此属性的类。 此字段为常量。

SUPPORTED

指示应用此属性的类不依赖于上下文是否具有同步。 此字段为常量。

属性

名称 说明
IsReEntrant

获取或设置一个布尔值,该值指示是否需要重新输入。

Locked

获取或设置一个布尔值,该值指示是否 Context 锁定了实现此实例 SynchronizationAttribute

Name

此 API 支持产品基础结构,不能在代码中直接使用。

获取上下文属性的名称。

(继承自 ContextAttribute)
TypeId

在派生类中实现时,获取此 Attribute的唯一标识符。

(继承自 Attribute)

方法

名称 说明
Equals(Object)

此 API 支持产品基础结构,不能在代码中直接使用。

返回一个布尔值,该值指示此实例是否等于指定的对象。

(继承自 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)

将一组名称映射为对应的一组调度标识符。

(继承自 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

检索对象的类型信息,该信息可用于获取接口的类型信息。

(继承自 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

检索对象提供的类型信息接口的数量(0 或 1)。

(继承自 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

提供对对象公开的属性和方法的访问。

(继承自 Attribute)

适用于