Este artículo se tradujo automáticamente. Para ver el artículo en inglés, active la casilla Inglés. Además, puede mostrar el texto en inglés en una ventana emergente si mueve el puntero del mouse sobre el texto.
Traducción
Inglés

Método Thread.BeginThreadAffinity ()

 

Publicado: octubre de 2016

Notifica a un host que el código administrado está a punto de ejecutar instrucciones que dependen de la identidad del subproceso del sistema operativo físico actual.

Espacio de nombres:   System.Threading
Ensamblado:  mscorlib (en mscorlib.dll)

[SecurityCriticalAttribute]
public static void BeginThreadAffinity()

Exception Condition
SecurityException

El llamador no dispone del permiso requerido.

Some hosts of the common language runtime, such as Microsoft SQL Server 2005, provide their own thread management. A host that provides its own thread management can move an executing task from one physical operating system thread to another at any time. Most tasks are not affected by this switching. However, some tasks have thread affinity - that is, they depend on the identity of a physical operating system thread. These tasks must inform the host when they execute code that should not be switched.

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 M:System.Threading.Thread.BeginThreadAffinity before acquiring the lock, and M:System.Threading.Thread.EndThreadAffinity after releasing the lock.

Using this method in code that runs under SQL Server 2005 requires the code to be run at the highest host protection level.

The following example demonstrates the use of the M:System.Threading.Thread.BeginThreadAffinity and M:System.Threading.Thread.EndThreadAffinity methods to notify a host that a block of code depends on the identity of a physical operating system thread.

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.
    }
}

SecurityCriticalAttribute

Requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

.NET Framework
Disponible desde 2.0
Volver al principio
Mostrar: