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;

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 など、共通言語ランタイムの一部のホストは、独自のスレッド管理を提供します。 独自のスレッド管理を提供するホストは、実行中のタスクを 1 つの物理オペレーティング システム スレッドから別のオペレーティング システム スレッドにいつでも移動できます。 ほとんどのタスクは、この切り替えの影響を受けません。 ただし、一部のタスクにはスレッド アフィニティがあります。つまり、物理オペレーティング システム スレッドの ID に依存します。 これらのタスクは、切り替えるべきでないコードを実行するときにホストに通知する必要があります。

たとえば、アプリケーションがシステム API を呼び出して、Win32 CRITICAL_SECTIONなどのスレッド アフィニティを持つオペレーティング システム ロックを取得する場合は、ロックを取得する前とEndThreadAffinityロックを解放した後に を呼び出BeginThreadAffinityす必要があります。

SQL Server 2005 で実行されるコードでこのメソッドを使用するには、最高のホスト保護レベルでコードを実行する必要があります。

適用対象

こちらもご覧ください