ThreadInterruptedException Sınıf

Tanım

bir bekleme durumundayken kesildiğinde Thread oluşan özel durum.

public ref class ThreadInterruptedException : SystemException
[System.Serializable]
public class ThreadInterruptedException : SystemException
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public class ThreadInterruptedException : SystemException
public class ThreadInterruptedException : SystemException
[<System.Serializable>]
type ThreadInterruptedException = class
    inherit SystemException
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type ThreadInterruptedException = class
    inherit SystemException
type ThreadInterruptedException = class
    inherit SystemException
Public Class ThreadInterruptedException
Inherits SystemException
Devralma
ThreadInterruptedException
Öznitelikler

Örnekler

Aşağıdaki kod örneği, kesintiye uğradığında ve daha sonra engellendiğinde çalışan bir iş parçacığının davranışını gösterir.

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

Açıklamalar

Bir iş parçacığı oluşturulduktan sonra, yok edilene kadar bir veya daha fazla ThreadState durumda olur. bir iş parçacığı durumunda olduğunda çağrısı Interrupt hedef iş WaitSleepJoin parçacığında bir ThreadInterruptedException oluşturulur neden olur. İş parçacığı durumunda değilse WaitSleepJoin , iş parçacığı bu duruma girene kadar özel durum atılmaz. İş parçacığı hiçbir zaman engellenmezse, kesintiye uğramadan görevini tamamlayabilir.

ThreadInterruptedException değeri 0x80131519 olan HRESULT COR_E_THREADINTERRUPTED kullanır.

ThreadInterruptedExceptionörneğinin ilk özellik değerlerinin listesi için bkz. ThreadInterruptedException oluşturucuları.

Oluşturucular

Name Description
ThreadInterruptedException()

Sınıfın ThreadInterruptedException yeni bir örneğini varsayılan özelliklerle başlatır.

ThreadInterruptedException(SerializationInfo, StreamingContext)

Serileştirilmiş verilerle ThreadInterruptedException sınıfının yeni bir örneğini başlatır.

ThreadInterruptedException(String, Exception)

Belirtilen bir hata iletisi ve bu özel durumun nedeni olan iç özel duruma başvuru ile ThreadInterruptedException sınıfının yeni bir örneğini başlatır.

ThreadInterruptedException(String)

Belirtilen bir hata iletisiyle sınıfının yeni bir örneğini ThreadInterruptedException başlatır.

Özellikler

Name Description
Data

Özel durum hakkında kullanıcı tanımlı ek bilgiler sağlayan anahtar/değer çiftleri koleksiyonunu alır.

(Devralındığı yer: Exception)
HelpLink

Bu özel durumla ilişkili yardım dosyasının bağlantısını alır veya ayarlar.

(Devralındığı yer: Exception)
HResult

Belirli bir özel duruma atanan kodlanmış sayısal bir değer olan HRESULT değerini alır veya ayarlar.

(Devralındığı yer: Exception)
InnerException

Geçerli özel duruma neden olan Exception örneğini alır.

(Devralındığı yer: Exception)
Message

Geçerli özel durumu açıklayan bir ileti alır.

(Devralındığı yer: Exception)
Source

Hataya neden olan uygulamanın veya nesnenin adını alır veya ayarlar.

(Devralındığı yer: Exception)
StackTrace

Çağrı yığınındaki anlık çerçevelerin dize gösterimini alır.

(Devralındığı yer: Exception)
TargetSite

Geçerli özel durumu oluşturan yöntemini alır.

(Devralındığı yer: Exception)

Yöntemler

Name Description
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetBaseException()

Türetilmiş bir sınıfta geçersiz kılındığında, sonraki bir veya daha fazla özel durumun kök nedeni olan Exception döndürür.

(Devralındığı yer: Exception)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetObjectData(SerializationInfo, StreamingContext)

Türetilmiş bir sınıfta geçersiz kılındığında, özel durumla ilgili bilgilerle SerializationInfo ayarlar.

(Devralındığı yer: Exception)
GetType()

Geçerli örneğin çalışma zamanı türünü alır.

(Devralındığı yer: Exception)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli özel durumun dize gösterimini oluşturur ve döndürür.

(Devralındığı yer: Exception)

Ekinlikler

Name Description
SerializeObjectState

Özel durum hakkında serileştirilmiş veriler içeren bir özel durum durumu nesnesi oluşturmak için bir özel durum seri hale getirildiğinde gerçekleşir.

(Devralındığı yer: Exception)

Şunlara uygulanır

Ayrıca bkz.