您的位置:首页 > 其它

线程启动一个不带参数的方法

2018-04-04 16:11 127 查看
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Thread t = new Thread(new ThreadStart(ShowTime));//注意ThreadStart委托的定义形式
t.Start();//线程开始,控制权返回Main线程
Console.WriteLine("主线程继续执行");
while (t.IsAlive == true) ;
Thread.Sleep(1000);
t.Abort();
t.Join();//阻塞Main线程,直到t终止
Console.WriteLine("--------------");
Console.ReadKey();
}
static void ShowTime()
{
while (true)
{
Console.WriteLine(DateTime.Now.ToString());
}
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: