public static void Addresult(object data) { if (data is AddNum) { Console.WriteLine("---启动{0}线程---", Thread.CurrentThread.Name); AddNum numbers = (AddNum)data; Console.WriteLine("{0}+{1}={2}", numbers.a, numbers.b, numbers.a + numbers.b); Console.WriteLine("---{0}线程结束---", Thread.CurrentThread.Name); } }
static void Main(string[] args) { Console.WriteLine("启动主线程:"); AddNum addnum = new AddNum(3, 5); ParameterizedThreadStart pthrstart = new ParameterizedThreadStart(ParameterThreadstartTest.Addresult); Thread mythr = new Thread(pthrstart); mythr.Name = "Subthr"; mythr.Start(addnum); //mythr.Join(); Console.WriteLine("主线程结束。"); Console.Read(); }