thread with multiple parameters

前端 未结 11 1646
一生所求
一生所求 2020-11-29 04:16

Does anyone know how to pass multiple parameters into a Thread.Start routine?

I thought of extending the class, but the C# Thread class is sealed.

Here is wh

11条回答
  •  孤街浪徒
    2020-11-29 05:02

    void RunFromHere()
    {
        string param1 = "hello";
        int param2 = 42;
    
        Thread thread = new Thread(delegate()
        {
            MyParametrizedMethod(param1,param2);
        });
        thread.Start();
    }
    
    void MyParametrizedMethod(string p,int i)
    {
    // some code.
    }
    

提交回复
热议问题