Program1 p1 = new Program1();
Thread th = new Thread(new ThreadStart(p1.ThreadRunMethord));//创建一个新的子线程
if (th.ThreadState != ThreadState.Running)//判断子线程未开始时运行
{
th.Start();//启动子线程
}
Thread.Sleep(1000);//主线程休眠1秒钟
Console.WriteLine("子线程被挂起而暂停");
if (th.ThreadState == ThreadState.Running)//若子线程为运行状态
{
th.Suspend();//线程被挂起而暂停
}
if (th.ThreadState == ThreadState.Suspended)//若子线程为挂起状态
{
th.Resume();//恢复子线程而继续执行
}
Console.WriteLine("恢复运行已挂起的子线程");//输出子线程已被恢复执行的信息
Console.ReadLine();
public void ThreadRunMethord()//子线程执行的方法
{
Console.WriteLine("子线程开始运行....");
}
Program1 p1 = new Program1();
Thread th = new Thread(new ThreadStart(p1.ThreadRunMethord));//创建一个新的子线程
if (th.ThreadState != ThreadState.Running)//判断子线程未开始时运行
{
th.Start();//启动子线程
}
Thread.Sleep(1000);//主线程休眠1秒钟
Console.WriteLine("子线程被挂起而暂停");
if (th.ThreadState == ThreadState.Running)//若子线程为运行状态
{
th.Abort();//子线程运行终止
}
if (th.ThreadState == ThreadState.Stopped)//若子线程已经停止
{
Console.WriteLine("线程已经终止");//输出子线程终止的信息
}
Console.ReadLine();
public void ThreadRunMethord()//子线程执行的方法
{
Console.WriteLine("子线程开始运行....");
}