ThreadAbortException.ExceptionState 속성

정의

스레드 중단에 관련된 애플리케이션 관련 정보가 포함된 개체를 가져옵니다.

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

속성 값

Object

애플리케이션 관련 정보가 포함된 개체입니다.

예제

다음 코드 예제에서는 중단 중인 스레드에 정보를 전달하는 방법을 보여줍니다.

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

설명

이 속성에서 반환 된 개체를 통해 지정 된 stateInfo 의 매개 변수는 Abort 메서드. 정확한 콘텐츠 및이 개체의 사용법은 애플리케이션 정의 합니다. 일반적으로 스레드 중단에 의미 있는 정보를 전달 하는 것이 됩니다.

적용 대상

추가 정보