学习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();
}
}
}
}
}
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();
}
}
}
}
}
解决方案 »
- 求正规则表达式!
- 细解对象克隆代码!!!
- 如何把asp:DropDownList做函数参数??
- 问一个关于算法的问题..求助
- notifyIcon 的问题
- 分少了看来还真不行.这里那么多人喜欢分..问一个C# winform访问3.5w access数据库.做LIKE查询.却数据溢出的问题.!
- 从串口读取数据,把需要的数据存入数据库出错
- 提问:在.NET网页中引入一个MATLAB创建的DLL文件,CS文件中的C#后天代码该如何写?
- 做SMTP客户端遇到的问题:535 Error: authentication failed
- 请问:在c#里,如何阻止改变窗体大小?
- Regex("asiatelecom_\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}_\\d{14})(\\w{6})$")
- C# 字符串打印问题
创建线程后,该线程将处于一个或多个 ThreadState 状态中,直到被销毁。调用 Interrupt 时,如果一个线程处于 WaitSleepJoin 状态,则将导致在目标线程中引发 ThreadInterruptedException。如果该线程未处于 WaitSleepJoin 状态,则直到该线程进入该状态时才会引发异常。如果该线程始终不阻塞,则它会顺利完成而不被中断。 ThreadInterruptedException 使用值为 0x80131519 的 HRESULT COR_E_THREADINTERRUPTED。有关 ThreadInterruptedException 实例的初始属性值列表,请参见 ThreadInterruptedException 构造
msdn说得已经够清楚了。