ThreadAbortException.ExceptionState Propiedad

Definición

Obtiene un objeto que contiene 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; }
member this.ExceptionState : obj
Public ReadOnly Property ExceptionState As Object

Valor de propiedad

Objeto que contiene información específica de la aplicación.

Ejemplos

En el ejemplo de código siguiente se muestra cómo pasar información a un subproceso que se está anulando.

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

Comentarios

El objeto devuelto por esta propiedad se especifica mediante el stateInfo parámetro del Abort método . El contenido exacto y el uso de este objeto se definen en la aplicación; normalmente se usa para transmitir información significativa al subproceso que se anula.

Se aplica a

Consulte también