线程操作之线程的挂起与恢复

线程的挂起是通过Thread类的Suspend方法实现的,Suspend方法将无限期的挂起当前线程,如再次执行当前线程,就需要将当前线程唤醒,这就要用到Thread类的Resume方法来唤醒线程。

成都创新互联拥有一支富有激情的企业网站制作团队,在互联网网站建设行业深耕十多年,专业且经验丰富。十多年网站优化营销经验,我们已为上1000+中小企业提供了成都网站建设、成都做网站解决方案,按需网站制作,设计满意,售后服务无忧。所有客户皆提供一年免费网站维护!


实例代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace 线程的挂起与恢复
{
class Program
{
public static void method()
{
for (int i = 0; i < 400; i++)
{
if (i % 40 == 0)
{
Console.WriteLine("");
}
else
{
Console.Write("");
}
}
}
static void Main(string[] args)
{
ThreadStart ts = new ThreadStart(method);
Thread t = new Thread(ts);
t.Start();
while (t.IsAlive)
{
t.Suspend();//挂起线程
Thread.Sleep(1000);//线程休眠一秒
t.Resume();//唤醒线程
}
Console.ReadKey();

}
}
}
本文题目:线程操作之线程的挂起与恢复
标题URL:http://bzwzjz.com/article/eshpsp.html

其他资讯

Copyright © 2007-2020 广东宝晨空调科技有限公司 All Rights Reserved 粤ICP备2022107769号
友情链接: 成都网站制作 成都网站建设 成都网站建设公司 网站制作 营销网站建设 网站制作公司 四川成都网站制作 定制网站设计 高端网站设计 成都响应式网站建设公司 重庆企业网站建设 成都网站制作 营销型网站建设 成都h5网站建设 古蔺网站建设 成都响应式网站建设 重庆手机网站建设 成都企业网站建设公司 网站建设公司 成都网站设计 阿坝网站设计 成都网站设计