快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

线程操作之线程休眠

线程的休眠是通过Thread类的Sleep方法实现的(休眠的时间是以毫秒为单位的),而Thread类的实例的IsAlive属性可以判断线程是否执行完毕,Sleep方法的使用格式为:

自流井ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为成都创新互联公司的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!


实例代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace 线程休眠
{
class Program
{
static void Main(string[] args)
{
ThreadStart ts = new ThreadStart(method);
Thread t = new Thread(ts);
t.Start();
while (t.IsAlive)
{
Console.WriteLine("线程开始执行!");
Thread.Sleep(1);//设置休眠时间为1毫秒
}
Console.ReadKey();
}
public static void method()
{
string state;
for (int i = 1; i < 5001; i++)
{
state = Thread.CurrentThread.ThreadState.ToString();
if (i % 5 == 0)
{
Console.WriteLine("当前线程状态为:{0}", state);
}
}
}
}
}
当前标题:线程操作之线程休眠
当前URL:http://6mz.cn/article/sjdpdo.html

其他资讯