110,533
社区成员
发帖
与我相关
我的任务
分享
static Thread t1;
public static void Main()
{
Console.WriteLine("Begin...");
t1 = new Thread(new ThreadStart(Sleep10));
t1.Start();
Thread t2 = new Thread(new ThreadStart(WakeUpT1));
t2.Start();
Console.WriteLine("End...");
Console.ReadLine();
}
/// <summary>
/// 睡眠十秒钟
/// </summary>
static void Sleep10()
{
Thread.Sleep(10000);
Console.WriteLine("10秒后才执行此语句");
}
/// <summary>
/// 中断线程
/// </summary>
static void WakeUpT1()
{
if (t1.ThreadState == System.Threading.ThreadState.WaitSleepJoin)
{
Console.WriteLine("线程1强制中断");
t1.Interrupt();
}
}