SynchronizationAttribute Classe

Definição

Impõe um domínio de sincronização para o contexto atual e todos os contextos que compartilham a mesma instância.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.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
Herança
SynchronizationAttribute
Atributos
Implementações

Exemplos

O exemplo de código a seguir demonstra o uso do SynchronizationAttribute .The following code example demonstrates the use of the SynchronizationAttribute. Para obter o código de exemplo completo, consulte o exemplo para a AsyncResult classe.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 

Comentários

Quando esse atributo é aplicado a um objeto, somente um thread pode ser executado em todos os contextos que compartilham uma instância dessa propriedade.When this attribute is applied to an object, only one thread can be executing in all contexts that share an instance of this property. Isso é feito ao contribuir com coletores que interceptam e serializam chamadas de entrada para os respectivos contextos.This is done by contributing sinks that intercept and serialize incoming calls for the respective contexts. Se a propriedade estiver marcada para reentrada, os textos explicativos também serão interceptados.If the property is marked for reentry, then callouts are intercepted too. A interceptação de texto explicativo permite que outros threads em espera insiram o domínio de sincronização para obter a taxa de transferência máxima.The callout interception allows other waiting threads to enter the synchronization domain for maximal throughput.

Observação

Há duas classes chamadas SynchronizationAttribute : uma no System.Runtime.Remoting.Contexts namespace e a outra no System.EnterpriseServices namespace.There are two classes named SynchronizationAttribute : one in the System.Runtime.Remoting.Contexts namespace, and the other in the System.EnterpriseServices namespace. A System.EnterpriseServices.SynchronizationAttribute classe dá suporte apenas a chamadas síncronas e pode ser usada somente com componentes atendidos.The System.EnterpriseServices.SynchronizationAttribute class supports only synchronous calls, and can be used only with serviced components. O System.Runtime.Remoting.Contexts.SynchronizationAttribute oferece suporte a chamadas síncronas e assíncronas e pode ser usado somente com objetos associados ao contexto.The System.Runtime.Remoting.Contexts.SynchronizationAttribute supports both synchronous and asynchronous calls, and can be used only with context bound objects. (Para obter mais informações sobre objetos vinculados a contexto, consulte a ContextBoundObject classe.)(For more information on context bound objects, see the ContextBoundObject class.)

Observação

Essa classe faz uma demanda de link e uma demanda de herança no nível de classe.This class makes a link demand and an inheritance demand at the class level. Um SecurityException é gerado quando o chamador imediato ou a classe derivada não tem permissão de infraestrutura.A SecurityException is thrown when either the immediate caller or the derived class does not have infrastructure permission. Para obter detalhes sobre as demandas de segurança, consulte demandas de link e demandas de herança.For details about security demands, see Link Demands and Inheritance Demands.

Construtores

SynchronizationAttribute()

Inicializa uma nova instância da classe SynchronizationAttribute com valores padrão.Initializes a new instance of the SynchronizationAttribute class with default values.

SynchronizationAttribute(Boolean)

Inicializa uma nova instância da classe SynchronizationAttribute com um valor booliano que indica se a reentrada é necessária.Initializes a new instance of the SynchronizationAttribute class with a Boolean value indicating whether reentry is required.

SynchronizationAttribute(Int32)

Inicializa uma nova instância da classe SynchronizationAttribute com um sinalizador que indica o comportamento do objeto ao qual esse atributo é aplicado.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)

Inicializa uma nova instância da classe SynchronizationAttribute com um sinalizador que indica o comportamento do objeto ao qual esse atributo é aplicado e um valor booliano que indica se a reentrada é necessária.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.

Campos

AttributeName

Esta API dá suporte à infraestrutura do produto e não deve ser usada diretamente do seu código.

Indica o nome do atributo de contexto.Indicates the name of the context attribute.

(Herdado de ContextAttribute)
NOT_SUPPORTED

Indica que a classe à qual esse atributo é aplicado não pode ser criada em um contexto que tenha sincronização.Indicates that the class to which this attribute is applied cannot be created in a context that has synchronization. Este campo é constante.This field is constant.

REQUIRED

Indica que a classe à qual esse atributo é aplicado deve ser criada em um contexto que tenha sincronização.Indicates that the class to which this attribute is applied must be created in a context that has synchronization. Este campo é constante.This field is constant.

REQUIRES_NEW

Indica que a classe à qual esse atributo é aplicado deve ser criada em um contexto com uma nova instância da propriedade de sincronização de cada vez.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. Este campo é constante.This field is constant.

SUPPORTED

Indica que a classe à qual esse atributo é aplicado não depende da presença da sincronização no contexto.Indicates that the class to which this attribute is applied is not dependent on whether the context has synchronization. Este campo é constante.This field is constant.

Propriedades

IsReEntrant

Obtém ou define um valor booliano que indica se a reentrada é necessária.Gets or sets a Boolean value indicating whether reentry is required.

Locked

Obtém ou define um valor booliano que indica se o Context implementar esta instância do SynchronizationAttribute está bloqueado.Gets or sets a Boolean value indicating whether the Context implementing this instance of SynchronizationAttribute is locked.

Name

Esta API dá suporte à infraestrutura do produto e não deve ser usada diretamente do seu código.

Obtém o nome do atributo de contexto.Gets the name of the context attribute.

(Herdado de ContextAttribute)
TypeId

Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute.

(Herdado de Attribute)

Métodos

Equals(Object)

Esta API dá suporte à infraestrutura do produto e não deve ser usada diretamente do seu código.

Retorna um valor booliano que indica se essa instância é igual ao objeto especificado.Returns a Boolean value indicating whether this instance is equal to the specified object.

(Herdado de ContextAttribute)
Freeze(Context)

Esta API dá suporte à infraestrutura do produto e não deve ser usada diretamente do seu código.

Chamado quando o contexto está congelado.Called when the context is frozen.

(Herdado de ContextAttribute)
GetClientContextSink(IMessageSink)

Cria um coletor CallOut e encadeia-o na frente da cadeia de coletores fornecida no limite do contexto na extremidade do cliente de uma chamada de comunicação remota.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()

Esta API dá suporte à infraestrutura do produto e não deve ser usada diretamente do seu código.

Retorna o código hash dessa instância de ContextAttribute.Returns the hashcode for this instance of ContextAttribute.

(Herdado de ContextAttribute)
GetPropertiesForNewContext(IConstructionCallMessage)

Adiciona a propriedade de contexto Synchronized à IConstructionCallMessage especificada.Adds the Synchronized context property to the specified IConstructionCallMessage.

GetServerContextSink(IMessageSink)

Cria um coletor de expedição sincronizado e encadeia-o na frente da cadeia de coletores fornecida no limite de contexto na extremidade do servidor de uma chamada de comunicação remota.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()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
IsContextOK(Context, IConstructionCallMessage)

Retorna um valor booliano que indica se o parâmetro de contexto atende aos requisitos do atributo de contexto.Returns a Boolean value indicating whether the context parameter meets the context attribute's requirements.

IsDefaultAttribute()

Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Herdado de Attribute)
IsNewContextOK(Context)

Esta API dá suporte à infraestrutura do produto e não deve ser usada diretamente do seu código.

Retorna um valor booliano que indica se a propriedade de contexto é compatível com o novo contexto.Returns a Boolean value indicating whether the context property is compatible with the new context.

(Herdado de ContextAttribute)
Match(Object)

Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Herdado de Attribute)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Implantações explícitas de interface

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

Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.Maps a set of names to a corresponding set of dispatch identifiers.

(Herdado de Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.Retrieves the type information for an object, which can be used to get the type information for an interface.

(Herdado de Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Herdado de Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Fornece acesso a propriedades e métodos expostos por um objeto.Provides access to properties and methods exposed by an object.

(Herdado de Attribute)

Aplica-se a