How to call a method that takes multiple parameters in a thread?

前端 未结 4 2065
無奈伤痛
無奈伤痛 2021-02-08 07:54

I am building a C# Desktop application. How do I call a method that takes multiple parameters in a thread. I have a method called Send(string arg1, string arg2, string arg3) , I

4条回答
  •  南旧
    南旧 (楼主)
    2021-02-08 08:23

    this may help. You can define your Send method as follows and then can use the parameters.

    string[] parameters = new string[3];
    parameters[0] = arg1;
    parameters[1] = arg2;
    parameters[1] = arg3;
    
    System.Threading.Thread SendingThread = new System.Threading.Thread(Send);
    SendingThread.Start(parameters);
    
    
    public void Send(object parameters)
    {
       Array arrayParameters = new object[3];
       arrayParameters = (Array)parameters;
       string str1 = (string)arrayParameters.GetValue(0);
       string str2 = (string)arrayParameters.GetValue(1);
       string str3 = (string)arrayParameters.GetValue(2);
    
       ///Following code here...
    }
    

提交回复
热议问题