System.Threading.Thread的使用及传递参数等总结

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
//线程启动One()
Thread t = new Thread(() => One());
t.Start();

//线程启动One(object p) 方法一(传递参数)
Thread tt = new Thread(() => One("mang"));
tt.Start();

//线程启动Two(object p) 方法二(传递参数)
Thread ttt = new Thread(new ParameterizedThreadStart(Two));
ttt.Start("mangmang");
Console.ReadLine();

//构造函数
//new Thread(ThreadStart start) 初始化Thread类的新实例
//start 类型:System.Threading.ThreadStart
// ThreadStart委托,它表示此线程开始执行时要调用的方法。
}

static void One()
{
Console.WriteLine("One");
}

static void One(object p)
{
Console.WriteLine("One's parameter is " + p.ToString());
}

static void Two(object p)
{
Console.WriteLine("Two's parameter is " + p.ToString());
}
}
}

posted on 2018-10-29 12:12  asdyzh  阅读(4013)  评论(0编辑  收藏  举报

导航