ThreadInterruptedException 클래스

정의

Thread가 대기 상태에서 중단되었을 때 throw되는 예외입니다.

public ref class ThreadInterruptedException : SystemException
public class ThreadInterruptedException : SystemException
[System.Serializable]
public class ThreadInterruptedException : SystemException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class ThreadInterruptedException : SystemException
type ThreadInterruptedException = class
    inherit SystemException
[<System.Serializable>]
type ThreadInterruptedException = class
    inherit SystemException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ThreadInterruptedException = class
    inherit SystemException
Public Class ThreadInterruptedException
Inherits SystemException
상속
ThreadInterruptedException
특성

예제

다음 코드 예제에서는 실행 중인 스레드가 중단되고 이후에 차단될 때의 동작을 보여 집니다.

using namespace System;
using namespace System::Security::Permissions;
using namespace System::Threading;

ref class StayAwake
{
private:
   bool sleepSwitch;

public:

   property bool SleepSwitch 
   {
      void set( bool value )
      {
         sleepSwitch = value;
      }

   }
   StayAwake()
   {
      sleepSwitch = false;
   }

   void ThreadMethod()
   {
      Console::WriteLine( "newThread is executing ThreadMethod." );
      while (  !sleepSwitch )
      {
         
         // Use SpinWait instead of Sleep to demonstrate the 
         // effect of calling Interrupt on a running thread.
         Thread::SpinWait( 10000000 );
      }

      try
      {
         Console::WriteLine( "newThread going to sleep." );
         
         // When newThread goes to sleep, it is immediately 
         // woken up by a ThreadInterruptedException.
         Thread::Sleep( Timeout::Infinite );
      }
      catch ( ThreadInterruptedException^ /*e*/ ) 
      {
         Console::WriteLine( "newThread cannot go to sleep - "
         "interrupted by main thread." );
      }

   }

};

int main()
{
   StayAwake^ stayAwake = gcnew StayAwake;
   Thread^ newThread = gcnew Thread( gcnew ThreadStart( stayAwake, &StayAwake::ThreadMethod ) );
   newThread->Start();
   
   // The following line causes an exception to be thrown 
   // in ThreadMethod if newThread is currently blocked
   // or becomes blocked in the future.
   newThread->Interrupt();
   Console::WriteLine( "Main thread calls Interrupt on newThread." );
   
   // Then tell newThread to go to sleep.
   stayAwake->SleepSwitch = true;
   
   // Wait for newThread to end.
   newThread->Join();
}
using System;
using System.Security.Permissions;
using System.Threading;

class ThreadInterrupt
{
    static void Main()
    {
        StayAwake stayAwake = new StayAwake();
        Thread newThread = 
            new Thread(new ThreadStart(stayAwake.ThreadMethod));
        newThread.Start();

        // The following line causes an exception to be thrown 
        // in ThreadMethod if newThread is currently blocked
        // or becomes blocked in the future.
        newThread.Interrupt();
        Console.WriteLine("Main thread calls Interrupt on newThread.");

        // Tell newThread to go to sleep.
        stayAwake.SleepSwitch = true;

        // Wait for newThread to end.
        newThread.Join();
    }
}

class StayAwake
{
    bool sleepSwitch = false;

    public bool SleepSwitch
    {
        set{ sleepSwitch = value; }
    }

    public StayAwake(){}

    public void ThreadMethod()
    {
        Console.WriteLine("newThread is executing ThreadMethod.");
        while(!sleepSwitch)
        {
            // Use SpinWait instead of Sleep to demonstrate the 
            // effect of calling Interrupt on a running thread.
            Thread.SpinWait(10000000);
        }
        try
        {
            Console.WriteLine("newThread going to sleep.");

            // When newThread goes to sleep, it is immediately 
            // woken up by a ThreadInterruptedException.
            Thread.Sleep(Timeout.Infinite);
        }
        catch(ThreadInterruptedException e)
        {
            Console.WriteLine("newThread cannot go to sleep - " +
                "interrupted by main thread.");
        }
    }
}
Option Explicit
Option Strict

Imports System.Security.Permissions
Imports System.Threading

Public Class ThreadInterrupt

    <MTAThread> _
    Shared Sub Main()
        Dim stayAwake As New StayAwake()
        Dim newThread As New Thread(AddressOf stayAwake.ThreadMethod)
        newThread.Start()

        ' The following line causes an exception to be thrown 
        ' in ThreadMethod if newThread is currently blocked
        ' or becomes blocked in the future.
        newThread.Interrupt()
        Console.WriteLine("Main thread calls Interrupt on newThread.")

        ' Tell newThread to go to sleep.
        stayAwake.SleepSwitch = True

        ' Wait for newThread to end.
        newThread.Join()
    End Sub

End Class

Public Class StayAwake

    Dim sleepSwitchValue As Boolean = False

    WriteOnly Property SleepSwitch As Boolean
        Set
            sleepSwitchValue = Value
        End Set
    End Property 

    Sub New()
    End Sub

    Sub ThreadMethod()
        Console.WriteLine("newThread is executing ThreadMethod.")
        While Not sleepSwitchValue

            ' Use SpinWait instead of Sleep to demonstrate the 
            ' effect of calling Interrupt on a running thread.
            Thread.SpinWait(10000000)
        End While
        Try
            Console.WriteLine("newThread going to sleep.")

            ' When newThread goes to sleep, it is immediately 
            ' woken up by a ThreadInterruptedException.
            Thread.Sleep(Timeout.Infinite)
        Catch ex As ThreadInterruptedException
            Console.WriteLine("newThread cannot go to " & _
                "sleep - interrupted by main thread.")
        End Try
    End Sub

End Class

설명

스레드를 만든 후에는 삭제될 때까지 하나 이상의 ThreadState 상태에 있습니다. 스레드가 WaitSleepJoin 상태에 있을 때 호출 Interrupt 하면 ThreadInterruptedException 대상 스레드에 throw됩니다. 스레드가 상태가 아니면 WaitSleepJoin 스레드가 해당 상태가 될 때까지 예외가 throw되지 않습니다. 스레드가 차단되지 않으면 중단 없이 완료될 수 있습니다.

ThreadInterruptedException 는 값이 0x80131519 HRESULT COR_E_THREADINTERRUPTED 사용합니다.

인스턴스의 초기 속성 값의 목록을 ThreadInterruptedException, 참조는 ThreadInterruptedException 생성자입니다.

생성자

ThreadInterruptedException()

기본 속성을 사용하여 ThreadInterruptedException 클래스의 새 인스턴스를 초기화합니다.

ThreadInterruptedException(SerializationInfo, StreamingContext)

serialize된 데이터를 사용하여 ThreadInterruptedException 클래스의 새 인스턴스를 초기화합니다.

ThreadInterruptedException(String)

지정된 오류 메시지를 사용하여 ThreadInterruptedException 클래스의 새 인스턴스를 초기화합니다.

ThreadInterruptedException(String, Exception)

지정된 오류 메시지와 해당 예외의 원인인 내부 예외에 대한 참조를 사용하여 ThreadInterruptedException 클래스의 새 인스턴스를 초기화합니다.

속성

Data

예외에 대한 사용자 정의 정보를 추가로 제공하는 키/값 쌍 컬렉션을 가져옵니다.

(다음에서 상속됨 Exception)
HelpLink

이 예외와 연결된 도움말 파일에 대한 링크를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
HResult

특정 예외에 할당된 코드화된 숫자 값인 HRESULT를 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
InnerException

현재 예외를 발생시킨 Exception 인스턴스를 가져옵니다.

(다음에서 상속됨 Exception)
Message

현재 예외를 설명하는 메시지를 가져옵니다.

(다음에서 상속됨 Exception)
Source

오류를 발생시키는 애플리케이션 또는 개체의 이름을 가져오거나 설정합니다.

(다음에서 상속됨 Exception)
StackTrace

호출 스택의 직접 실행 프레임 문자열 표현을 가져옵니다.

(다음에서 상속됨 Exception)
TargetSite

현재 예외를 throw하는 메서드를 가져옵니다.

(다음에서 상속됨 Exception)

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetBaseException()

파생 클래스에서 재정의된 경우 하나 이상의 후속 예외의 근본 원인이 되는 Exception 을 반환합니다.

(다음에서 상속됨 Exception)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetObjectData(SerializationInfo, StreamingContext)

파생 클래스에서 재정의된 경우 예외에 관한 정보를 SerializationInfo 에 설정합니다.

(다음에서 상속됨 Exception)
GetType()

현재 인스턴스의 런타임 형식을 가져옵니다.

(다음에서 상속됨 Exception)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 예외에 대한 문자열 표현을 만들고 반환합니다.

(다음에서 상속됨 Exception)

이벤트

SerializeObjectState
사용되지 않습니다.

예외에 대한 serialize된 데이터가 들어 있는 예외 상태 개체가 만들어지도록 예외가 serialize될 때 발생합니다.

(다음에서 상속됨 Exception)

적용 대상

추가 정보