Notifica a un host que la ejecución está a punto de entrar en una región del código donde los efectos de una anulación del subproceso o de una excepción no controlada podrían constituir un riesgo para otras tareas del dominio de aplicaciones.
Espacio de nombres: System.Threading
Ensamblado: mscorlib (en mscorlib.dll)

Sintaxis
Visual Basic (Declaración)
Public Shared Sub BeginCriticalRegion
Thread.BeginCriticalRegion
public static void BeginCriticalRegion ()
public:
static void BeginCriticalRegion ()
public static void BeginCriticalRegion ()
public static function BeginCriticalRegion ()

Comentarios
Los hosts de Common Language Runtime (CLR), como "Yukon" de Microsoft® SQL Server, pueden establecer directivas diferentes para los errores que se produzcan en regiones críticas y no críticas del código. Una región crítica es aquélla donde los efectos de una anulación de un subproceso o de una excepción no controlada podrían no limitarse a la tarea actual. En cambio, una anulación o un error en una región no crítica del código afecta únicamente a la tarea donde se produce el error.
Por ejemplo, consideremos una tarea que intenta asignar memoria mientras mantiene un bloqueo. Si se produce un error al asignar la memoria, no basta con anular la tarea actual para garantizar estabilidad de AppDomain, porque puede haber otras tareas en el dominio esperando el mismo bloqueo. Si se finaliza la tarea actual, otras tareas podrían sufrir un interbloqueo.
Cuando se produce un error en una región crítica, el host puede optar por descargar el AppDomain completo en lugar de arriesgarse a continuar con la ejecución en un estado potencialmente inestable. Para informar al host de que el código está entrando en una región crítica, se llama a BeginCriticalRegion. Llame a EndCriticalRegion cuando la ejecución regrese a una región no crítica del código.
Para usar este método en código que se ejecuta en el servidor "Yukon" de SQL Server, es obligatorio que el código se ejecute en el máximo nivel de protección del host.

Ejemplo
El ejemplo siguiente muestra el uso de los métodos BeginCriticalRegion y EndCriticalRegion para dividir un bloque de código en regiones críticas y no críticas.
Imports System.Threading
Public Class MyUtility
Public Sub PerformTask()
' Code in this region can be aborted without affecting
' other tasks.
'
Thread.BeginCriticalRegion()
'
' The host might decide to unload the application domain
' if a failure occurs in this code region.
'
Thread.EndCriticalRegion()
' Code in this region can be aborted without affecting
' other tasks.
End Sub
End Class
using System.Threading;
public class MyUtility
{
public void PerformTask()
{
// Code in this region can be aborted without affecting
// other tasks.
//
Thread.BeginCriticalRegion();
//
// The host might decide to unload the application domain
// if a failure occurs in this code region.
//
Thread.EndCriticalRegion();
//
// Code in this region can be aborted without affecting
// other tasks.
}
}
using namespace System::Threading;
public ref class MyUtility
{
public:
void PerformTask()
{
// Code in this region can be aborted without affecting
// other tasks.
//
Thread::BeginCriticalRegion();
//
// The host might decide to unload the application domain
// if a failure occurs in this code region.
//
Thread::EndCriticalRegion();
//
// Code in this region can be aborted without affecting
// other tasks.
}
};
import System.Threading.*;
import System.Threading.Thread;
public class MyUtility
{
public void PerformTask()
{
// Code in this region can be aborted without affecting
// other tasks.
//
Thread.BeginCriticalRegion();
//
// The host might decide to unload the application domain
// if a failure occurs in this code region.
//
Thread.EndCriticalRegion();
// Code in this region can be aborted without affecting
// other tasks.
} //PerformTask
} //MyUtility

Plataformas
Windows 98, Windows 2000 Service Pack 4, Windows Millennium, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter
Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

Información de versión
.NET Framework
Compatible con: 3.0, 2.0

Vea también