public class ThreadStartTest
{
//无参数的构造函数
Thread thread = new Thread(new ThreadStart(ThreadMethod));
//带有object参数的构造函数
Thread thread2 = new Thread(new ParameterizedThreadStart(ThreadMethodWithPara));
public ThreadStartTest()
{
//启动线程1
thread.Start();
//启动线程2
thread2.Start(new Parameter { paraName="Test" });
}
static void ThreadMethod()
{
//....
}
static void ThreadMethodWithPara(object o)
{
if (o is Parameter)
{
// (o as Parameter).paraName.............
}
}
}
public class Parameter
{
public string paraName { get; set; }
}
使得当前线程休眠(暂时停止执行millis毫秒)
thread.sleep(3000)
阻塞其他线程,自己执行
当NewThread调用Join方法的时候,MainThread就被停止执行,
直到NewThread线程执行完毕
thread.join()
多个线程依次执行例子:
public static void ThreadJoin2()
{
IList<Thread> threads = new List<Thread>();
for (int i = 0; i < 3; i++)
{
Thread t = new Thread(
new ThreadStart(
() =>
{