ThreadAbortException.ExceptionState ThreadAbortException.ExceptionState ThreadAbortException.ExceptionState ThreadAbortException.ExceptionState Property

Definition

Ruft ein Objekt ab, das anwendungsspezifische Informationen über den Threadabbruch enthält.Gets an object that contains application-specific information related to the thread abort.

public:
 property System::Object ^ ExceptionState { System::Object ^ get(); };
public object ExceptionState { get; }
member this.ExceptionState : obj
Public ReadOnly Property ExceptionState As Object

Eigenschaftswert

Ein Objekt, das anwendungsspezifische Informationen enthält.An object containing application-specific information.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, Informationen an einen Thread zu übergeben, die abgebrochen wird.The following code example shows how to pass information to a thread that is being aborted.

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
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

Hinweise

Von dieser Eigenschaft zurückgegebenen Objekts angegeben ist, über die stateInfo Parameter der Abort Methode.The object returned by this property is specified through the stateInfo parameter of the Abort method. Der genaue Inhalt und die Verwendung dieses Objekts ist Anwendungsdefiniert. Es wird normalerweise verwendet, um Informationen zu übermitteln, die für den Thread abgebrochen von Bedeutung ist.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.

Gilt für:

Siehe auch