ThreadAbortException::ExceptionState Property
.NET Framework (current version)
Gets an object that contains application-specific information related to the thread abort.
Assembly: mscorlib (in mscorlib.dll)
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
Available since 1.1
Show: