Thread.EndThreadAffinity Método
Definição
Notifica um host que o código gerenciado terminou de executar as instruções que dependem da identidade do thread do sistema operacional físico atual.Notifies a host that managed code has finished executing instructions that depend on the identity of the current physical operating system thread.
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 ()
- Atributos
Exceções
O chamador não tem a permissão necessária.The caller does not have the required permission.
Exemplos
O exemplo a seguir demonstra o uso dos BeginThreadAffinity EndThreadAffinity métodos e para notificar um host de que um bloco de código depende da identidade de um thread de sistema operacional físico.The following example demonstrates the use of the BeginThreadAffinity and EndThreadAffinity methods to notify a host that a block of code depends on the identity of a physical operating system thread.
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
Comentários
Alguns hosts da Common Language Runtime, como Microsoft SQL Server 2005, fornecem seu próprio gerenciamento de threads.Some hosts of the common language runtime, such as Microsoft SQL Server 2005, provide their own thread management. Um host que fornece seu próprio gerenciamento de threads pode mover uma tarefa em execução de um thread de sistema operacional físico para outro a qualquer momento.A host that provides its own thread management can move an executing task from one physical operating system thread to another at any time. A maioria das tarefas não é afetada por essa alternância.Most tasks are not affected by this switching. No entanto, algumas tarefas têm afinidade de thread – ou seja, elas dependem da identidade de um thread de sistema operacional físico.However, some tasks have thread affinity - that is, they depend on the identity of a physical operating system thread. Essas tarefas devem informar ao host quando eles executam o código que não deve ser alternado.These tasks must inform the host when they execute code that should not be switched.
Por exemplo, se o aplicativo chamar uma API do sistema para adquirir um bloqueio do sistema operacional que tenha afinidade de thread, como um CRITICAL_SECTION Win32, você deverá chamar BeginThreadAffinity antes de adquirir o bloqueio e EndThreadAffinity depois de liberar o bloqueio.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 BeginThreadAffinity before acquiring the lock, and EndThreadAffinity after releasing the lock.
Usar esse método no código que é executado em SQL Server 2005 requer que o código seja executado no nível de proteção de host mais alto.Using this method in code that runs under SQL Server 2005 requires the code to be run at the highest host protection level.