System.Threading.Thread.BeginThreadAffinity Method

Notifies a host that managed code is about to execute instructions that depend on the identity of the current physical operating system thread.

Syntax

[System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.WillNotCorruptState, System.Runtime.ConstrainedExecution.Cer.MayFail)]
public static void BeginThreadAffinity ()

Remarks

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 Thread.BeginThreadAffinity before acquiring the lock, and 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.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0