线程的创建
class Program {
static void Main(string[] args) {
// 使用无参数委托ThreadStart
Thread t = new Thread(wucan);
t.Start();
// 使用带参数委托ParameterizedThreadStart
Thread t2 = new Thread(youcan);
t2.Start("chuanru");
t2.Join();// 等待线程t2完成。
Console.WriteLine("Thread t2 已经执行完成");
Console.ReadKey();
}
static void wucan() {
Console.WriteLine("wucan!");
}
static void GoWithParam(object msg) {
Console.WriteLine("msg:" + msg);
Thread.Sleep(1000);// 模拟耗时操作
}
}
若标题中有“转载”字样,则本文版权归原作者所有。若无转载字样,本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

浙公网安备 33010602011771号