ThreadAbortException::ExceptionState Property

 

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

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

public:
property Object^ ExceptionState {
	Object^ 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 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." );
}

.NET Framework
Available since 1.1
Return to top
Show: