Thread.EndThreadAffinity 메서드

정의

호스트에 관리 코드가 현재 물리적 운영 체제 스레드의 ID에 따라 달라지는 명령 실행을 완료했음을 알 수 있습니다.

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

예외

호출자에게 필요한 권한이 없습니다.

예제

다음 예제에서는 코드 블록이 실제 운영 체제 스레드의 BeginThreadAffinity ID에 따라 달라지도록 호스트에 알리기 위해 메서드와 EndThreadAffinity 메서드를 사용하는 방법을 보여 줍니다.

using System.Threading;

public class MyUtility
{
    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.
    }
}
open System.Threading

let 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

설명

Microsoft SQL Server 2005와 같은 공용 언어 런타임의 일부 호스트는 자체 스레드 관리를 제공합니다. 자체 스레드 관리를 제공하는 호스트는 언제든지 실행 중인 작업을 한 실제 운영 체제 스레드에서 다른 스레드로 이동할 수 있습니다. 대부분의 작업은 이 전환의 영향을 받지 않습니다. 그러나 일부 작업에는 스레드 선호도가 있습니다. 즉, 실제 운영 체제 스레드의 ID에 따라 달라집니다. 이러한 작업은 전환해서는 안 되는 코드를 실행할 때 호스트에 알려야 합니다.

예를 들어 애플리케이션이 시스템 API를 호출하여 Win32 CRITICAL_SECTION 같은 스레드 선호도가 있는 운영 체제 잠금을 획득하는 경우 잠금 BeginThreadAffinity 을 획득하기 전에 잠금을 해제한 후 호출 EndThreadAffinity 해야 합니다.

SQL Server 2005에서 실행되는 코드에서 이 메서드를 사용하려면 가장 높은 호스트 보호 수준에서 코드를 실행해야 합니다.

적용 대상

추가 정보