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 및 메서드를 사용 하 여 EndThreadAffinity 코드 블록이 실제 운영 체제 스레드의 id에 따라 달라 지는 것을 호스트에 알리는 방법을 보여 줍니다.

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

설명

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

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

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

적용 대상

추가 정보