Thread.EndThreadAffinity Método

Definición

Notifica a un host que el código administrado ha terminado de ejecutar instrucciones que dependen de la identidad del subproceso del sistema operativo físico actual.Notifies a host that managed code has finished executing instructions that depend on the identity of the current physical operating system thread.

public:
 static void EndThreadAffinity();
[System.Security.SecurityCritical]
public static void EndThreadAffinity ();
static member EndThreadAffinity : unit -> unit
Public Shared Sub EndThreadAffinity ()
Atributos

Excepciones

El llamador no dispone del permiso requerido.The caller does not have the required permission.

Ejemplos

En el ejemplo siguiente se muestra el uso de los métodos BeginThreadAffinity y EndThreadAffinity para notificar a un host que un bloque de código depende de la identidad de un subproceso del sistema operativo físico.The following example demonstrates the use of the BeginThreadAffinity and EndThreadAffinity methods to notify a host that a block of code depends on the identity of a physical operating system thread.

using namespace System::Threading;
using namespace System::Security::Permissions;

public ref class MyUtility
{
public:
   [SecurityPermissionAttribute(SecurityAction::Demand, ControlThread=true)]
   void PerformTask()
   {
      // Code that does not have thread affinity goes here.
      //
      Thread::BeginThreadAffinity();
      //
      // Code that has thread affinity goes here.
      //
      Thread::EndThreadAffinity();
      //
      // More code that does not have thread affinity.
   }
};
using System.Threading;
using System.Security.Permissions;

[SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlThread)]
public class MyUtility
{
    [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.ControlThread)]
    public void PerformTask()
    {
        // Code that does not have thread affinity goes here.
        //
        Thread.BeginThreadAffinity();
        //
        // Code that has thread affinity goes here.
        //
        Thread.EndThreadAffinity();
        //
        // More code that does not have thread affinity.
    }
}
Imports System.Threading
Imports System.Security.Permissions

<SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.ControlThread)> _
Friend Class MyUtility
    <SecurityPermission(SecurityAction.Demand, Flags:=SecurityPermissionFlag.ControlThread)> _
    Public Sub PerformTask() 
        ' Code that does not have thread affinity goes here.
        '
        Thread.BeginThreadAffinity()
        '
        ' Code that has thread affinity goes here.
        '
        Thread.EndThreadAffinity()
        '
        ' More code that does not have thread affinity.
    End Sub
End Class

Comentarios

Algunos hosts del Common Language Runtime, como Microsoft SQL Server 2005, proporcionan su propia administración de subprocesos.Some hosts of the common language runtime, such as Microsoft SQL Server 2005, provide their own thread management. Un host que proporciona su propia administración de subprocesos puede trasladar una tarea en ejecución de un subproceso del sistema operativo físico a otro en cualquier momento.A host that provides its own thread management can move an executing task from one physical operating system thread to another at any time. La mayoría de las tareas no se ven afectadas por este cambio.Most tasks are not affected by this switching. Sin embargo, algunas tareas tienen afinidad de subprocesos, es decir, dependen de la identidad de un subproceso del sistema operativo físico.However, some tasks have thread affinity - that is, they depend on the identity of a physical operating system thread. Estas tareas deben informar al host cuando ejecuten código que no debe cambiarse.These tasks must inform the host when they execute code that should not be switched.

Por ejemplo, si la aplicación llama a una API del sistema para adquirir un bloqueo del sistema operativo que tiene afinidad de subprocesos, como una CRITICAL_SECTION de Win32, debe llamar a BeginThreadAffinity antes de adquirir el bloqueo y EndThreadAffinity después de liberar el bloqueo.For example, if your application calls a system API to acquire an operating system lock that has thread affinity, such as a Win32 CRITICAL_SECTION, you must call BeginThreadAffinity before acquiring the lock, and EndThreadAffinity after releasing the lock.

El uso de este método en el código que se ejecuta en SQL Server 2005 requiere que el código se ejecute en el nivel de protección del host más alto.Using this method in code that runs under SQL Server 2005 requires the code to be run at the highest host protection level.

Seguridad

SecurityCriticalAttribute
Requiere plena confianza para el llamador inmediato.Requires full trust for the immediate caller. Este miembro no puede ser utilizado por código transparente o de confianza parcial.This member cannot be used by partially trusted or transparent code.

Se aplica a

Consulte también: