ThreadAbortException.ExceptionState Propiedad
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene un objeto que contiene la información específica de la aplicación relacionada con la anulación del subproceso.
public:
property System::Object ^ ExceptionState { System::Object ^ get(); };
public object? ExceptionState { get; }
public object ExceptionState { get; }
member this.ExceptionState : obj
Public ReadOnly Property ExceptionState As Object
Objeto que contiene la información específica de la aplicación.
En el ejemplo de código siguiente se muestra cómo pasar información a un subproceso que se está anulando.
using namespace System;
using namespace System::Threading;
ref class Test
{
private:
Test(){}
public:
static void TestMethod()
{
try
{
while ( true )
{
Console::WriteLine( "New thread running." );
Thread::Sleep( 1000 );
}
}
catch ( ThreadAbortException^ abortException )
{
Console::WriteLine( dynamic_cast<String^>(abortException->ExceptionState) );
}
}
};
int main()
{
Thread^ newThread = gcnew Thread( gcnew ThreadStart( &Test::TestMethod ) );
newThread->Start();
Thread::Sleep( 1000 );
// Abort newThread.
Console::WriteLine( "Main aborting new thread." );
newThread->Abort( "Information from main." );
// Wait for the thread to terminate.
newThread->Join();
Console::WriteLine( "New thread terminated - main exiting." );
}
using System;
using System.Threading;
class Test
{
public static void Main()
{
Thread newThread = new Thread(new ThreadStart(TestMethod));
newThread.Start();
Thread.Sleep(1000);
// Abort newThread.
Console.WriteLine("Main aborting new thread.");
newThread.Abort("Information from Main.");
// Wait for the thread to terminate.
newThread.Join();
Console.WriteLine("New thread terminated - Main exiting.");
}
static void TestMethod()
{
try
{
while(true)
{
Console.WriteLine("New thread running.");
Thread.Sleep(1000);
}
}
catch(ThreadAbortException abortException)
{
Console.WriteLine((string)abortException.ExceptionState);
}
}
}
Imports System.Threading
Public Class Test
<MTAThread> _
Shared Sub Main()
Dim newThread As New Thread(AddressOf TestMethod)
newThread.Start()
Thread.Sleep(1000)
' Abort newThread.
Console.WriteLine("Main aborting new thread.")
newThread.Abort("Information from Main.")
' Wait for the thread to terminate.
newThread.Join()
Console.WriteLine("New thread terminated - Main exiting.")
End Sub
Shared Sub TestMethod()
Try
While True
Console.WriteLine("New thread running.")
Thread.Sleep(1000)
End While
Catch abortException As ThreadAbortException
Console.WriteLine( _
CType(abortException.ExceptionState, String))
End Try
End Sub
End Class
El objeto devuelto por esta propiedad se especifica a través del stateInfo
parámetro del Abort método . El contenido exacto y el uso de este objeto son definidos por la aplicación; normalmente se usa para transmitir información que es significativa para el subproceso que se está anulando.
Producto | Versiones |
---|---|
.NET | Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 2.0, 2.1 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: