您的位置:首页 > 其它

启动一个线程是用 run() 还是 start()?

2013-04-20 19:19 399 查看
启动一个线程是调用 start() 方法。

View Code

using System;
using System.Threading;

public class ThreadWork
{
public static void DoWork()
{
for (int i = 0; i < 3; i++)
{
Console.WriteLine("Working thread...");
Thread.Sleep(100);
}
}
}

class ThreadTest
{
public static void Main()
{
ThreadStart myThreadDelegate = new ThreadStart(ThreadWork.DoWork);
Thread myThread = new Thread(myThreadDelegate);
// 启动一个线程是调用 start() 方法。
myThread.Start();
for (int i = 0; i < 3; i++)
{
Console.WriteLine("In main.");
Thread.Sleep(100);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: