C#创建线程传递参数

class SimpleDialog : Form
{
    public static void Main()
    {
        Thread t = new Thread(new ParameterizedThreadStart(B));//ParameterizedThreadStart 是委托,参数是函数名
        t.Start("B");//Start的参数类型是 object
    }
    private static void B(object obj)
    {
        Console.WriteLine( (string)obj);
    }  
}
   Thread myThread = new Thread(new ParameterizedThreadStart(ThreadFunc));
        myThread.Start(2);

    static void ThreadFunc(object param)
    {
        int value = (int)param;
        Console.WriteLine("Thread param: "+ value.ToString());
        
    }


阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭