ThreadAbortException.ExceptionState Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets an object that contains application-specific information related to the thread abort.

Namespace:   System.Threading
Assembly:  mscorlib (in mscorlib.dll)

public object ExceptionState { get; }

Property Value

Type: System.Object

An object containing application-specific information.

The object returned by this property is specified through the stateInfo parameter of the Abort method. The exact content and usage of this object is application defined; it is typically used to convey information that is meaningful to the thread being aborted.

The following code example shows how to pass information to a thread that is being aborted.

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);
        }
    }
}

.NET Framework
Available since 1.1
Return to top
Show: