ThreadAbortException.ExceptionState-Eigenschaft
Ruft ein Objekt ab, das anwendungsspezifische Informationen über den Threadabbruch enthält.
Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public ReadOnly Property ExceptionState As Object
'Usage
Dim instance As ThreadAbortException
Dim value As Object
value = instance.ExceptionState
public Object ExceptionState { get; }
public:
property Object^ ExceptionState {
Object^ get ();
}
/** @property */
public Object get_ExceptionState ()
public function get ExceptionState () : Object
Eigenschaftenwert
Ein Objekt, das anwendungsspezifische Informationen enthält.
Hinweise
Das von dieser Eigenschaft zurückgegebene Objekt wird durch den stateInfo-Parameter der Abort-Methode angegeben. Der genaue Inhalt und die genaue Verwendung dieses Objekts ist anwendungsdefiniert. Im Allgemeinen werden damit Informationen übermittelt, die für den abzubrechenden Thread von Bedeutung sind.
Beispiel
Das folgende Codebeispiel veranschaulicht, wie Informationen an einen Thread übergeben werden, der abgebrochen wird.
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
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);
}
}
}
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." );
}
import System.*;
import System.Threading.*;
import System.Threading.Thread;
class Test
{
public static void main(String[] args)
{
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.");
} //main
static void TestMethod()
{
try {
while (true) {
Console.WriteLine("New thread running.");
Thread.Sleep(1000);
}
}
catch (ThreadAbortException abortException) {
Console.WriteLine((System.String)(abortException.
get_ExceptionState()));
}
} //TestMethod
} //Test
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0
Siehe auch
Referenz
ThreadAbortException-Klasse
ThreadAbortException-Member
System.Threading-Namespace
Thread.CurrentThread-Eigenschaft
Thread.Abort