学习C#线程手册的代码出来如题的问题
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;namespace Interrupt
{
    class Program
    {
        public static Thread sleeper;
        public static Thread worker;
        static void Main(string[] args)
        {
            Console.WriteLine("进入 void Main!");
            sleeper = new Thread(new ThreadStart(SleepingThread));
            worker = new Thread(new ThreadStart(AwakeTheTread)); 
            sleeper.Start();
            worker.Start();
            Console.WriteLine("退出 void Main!");
            Console.ReadLine();
        }
        public static void SleepingThread()
        {
            for (int i = 1; i < 50; i++)
            {
                Console.Write(i + "");
                if (i == 10 )
                {
                    Console.WriteLine("Goint go sleep at:" + i);
                    Thread.Sleep(2000);
                }
            }
        }
        public static void AwakeTheTread()
        {
            for (int i = 51; i < 100; i++)
            {
                Console.Write(i + " ");
                if (sleeper.ThreadState == ThreadState.WaitSleepJoin)
                {
                    Console.WriteLine("Interrupting the sleeping thread");
                    sleeper.Interrupt();
                }
            }
        }
    }
}

解决方案 »

  1.   

    如果对处于阻塞状态的线程调用Thread.Interrupt()方法将使线程状态改变,但是会抛出ThreadInterupptedException异常,你可以捕获这个异常并且做出处理。
      

  2.   

    备注
    创建线程后,该线程将处于一个或多个 ThreadState 状态中,直到被销毁。调用 Interrupt 时,如果一个线程处于 WaitSleepJoin 状态,则将导致在目标线程中引发 ThreadInterruptedException。如果该线程未处于 WaitSleepJoin 状态,则直到该线程进入该状态时才会引发异常。如果该线程始终不阻塞,则它会顺利完成而不被中断。 ThreadInterruptedException 使用值为 0x80131519 的 HRESULT COR_E_THREADINTERRUPTED。有关 ThreadInterruptedException 实例的初始属性值列表,请参见 ThreadInterruptedException 构造
    msdn说得已经够清楚了。
      

  3.   

    Interrupt是非常不推荐使用的,因为你无法精确知道他产生什么样的结果