class Program { static void Main(string[] args) { Work work = new Work();
//两种实例化委托的方法; //ParameterizedThreadStart ParameterizedThreadStartDelegate = new ParameterizedThreadStart(work.DoWork); ParameterizedThreadStart ParameterizedThreadStartDelegate = work.DoWork; Thread thread = new Thread(ParameterizedThreadStartDelegate); thread.Start(5); //参数 Console.ReadKey(); } }
public void DoWork(Object t) { for (int i = 0; i <= (int)t; i++) { Console.WriteLine("请打印{0}\n", i); } }
此例犯错原因:ParameterizedThreadStart和ThreadStart不要重新定义委托。
|
请发表评论