行远-自迩

导航

C#之线程ParameterizedThreadStart

    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不要重新定义委托。

posted on 2019-07-08 11:25  行远-自迩  阅读(3052)  评论(0编辑  收藏  举报