using System
using SystemThreading
namespace ThreadTest
{
public class A { public static void B()
{ while (true)
{ ConsoleWriteLine(AB is running in its own thread)}
public class C { public static void Main()
{ Thread t = new Thread(new ThreadStart(AB))tStart()ThreadSleep()tAbort()tJoin()ConsoleWriteLine(AB has finished)ConsoleReadLine()}
}
运行后显示若干行AB is running in its own thread和一行AB has finished
若取消程序中的ThreadSleep()句则运行后只显示AB has finished
理解如无ThreadSleep()句则线程oThread一开始后即被中止根据没有执行其中的代码但增加此句后使主线程sleep了毫秒这段时间使thread获得了资源得到了执行