Thread.EndThreadAffinity メソッド
アセンブリ: mscorlib (mscorlib.dll 内)



共通言語ランタイムの一部のホスト (たとえば Microsoft® SQL Server "Yukon") では、独自のスレッド管理機能が用意されています。独自のスレッド管理機能を持つホストは、いつでも実行タスクをオペレーティング システムの物理スレッド間で移動できます。ほとんどのタスクはこの切り替えの影響を受けません。ただし、一部のタスクにはスレッド アフィニティがあります。つまり、これらのタスクは、オペレーティング システムの物理スレッドの ID に依存します。これらのタスクは、切り替えてはいけないコードを実行するときにホストに通知する必要があります。
たとえば、Win32 CRITICAL_SECTION のようなスレッド アフィニティを持つオペレーティング システムのロックを取得するシステム API をアプリケーションで呼び出す場合、このロックを取得する前に BeginThreadAffinity を呼び出し、ロックを解放した後に EndThreadAffinity を呼び出す必要があります。
SQL Server "Yukon" で実行するコード内でこのメソッドを使用するには、ホストの保護レベルを最大にしてコードを実行する必要があります。

BeginThreadAffinity メソッドおよび EndThreadAffinity メソッドを使用してコード ブロックがオペレーティング システムの物理スレッドの ID に依存することをホストに通知する例を次に示します。
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 'PerformTask End Class 'MyUtility
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. } }
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. } };


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からThread.EndThreadAffinity メソッドを検索する場合は、下記のリンクをクリックしてください。

- Thread.EndThreadAffinity メソッドのページへのリンク