thread with multiple parameters thread with multiple parameters multithreading multithreading

thread with multiple parameters


Try using a lambda expression to capture the arguments.

Thread standardTCPServerThread =   new Thread(    unused => startSocketServerAsThread(initializeMemberBalance, arg, 60000)  );


Here is a bit of code that uses the object array approach mentioned here a couple times.

    ...    string p1 = "Yada yada.";    long p2 = 4715821396025;    int p3 = 4096;    object args = new object[3] { p1, p2, p3 };    Thread b1 = new Thread(new ParameterizedThreadStart(worker));    b1.Start(args);    ...    private void worker(object args)    {      Array argArray = new object[3];      argArray = (Array)args;      string p1 = (string)argArray.GetValue(0);      long p2 = (long)argArray.GetValue(1);      int p3 = (int)argArray.GetValue(2);      ...    }>


You need to wrap them into a single object.

Making a custom class to pass in your parameters is one option. You can also use an array or list of objects, and set all of your parameters in that.