Thread构造函数(ParameterizedThreadStart)使用示例

在多线程编程中,有时需向线程调用的方法传入参数,使用Thread构造函数(ParameterizedThreadStart)可以实现:

using System;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Thread thread = new Thread(DoWork);
            thread.Start("thread start.");//这边传入参数

            Console.ReadKey();
        }

        static void DoWork(object arg)
        {
            Console.WriteLine(arg.ToString());
        }
    }
}


评论: 0 | 引用: 0 | 查看次数: 3461
发表评论
登录后再发表评论!