线程与多参数线程、参数

由网友(斯文先生)分享简介:有谁知道如何将多个参数传递到Thread.Start程序?Does anyone know how to pass multiple parameters into a Thread.Start routine?我想扩展类,但C#Thread类是密封的。I thought of extending the cla...

有谁知道如何将多个参数传递到Thread.Start程序?

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

我想扩展类,但C#Thread类是密封的。

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

下面是我认为的code看起来像:

Here is what I think the code would look like:

...
    Thread standardTCPServerThread = new Thread(startSocketServerAsThread);

    standardServerThread.Start( orchestrator, initializeMemberBalance, arg, 60000);
...
}

static void startSocketServerAsThread(ServiceOrchestrator orchestrator, List<int> memberBalances, string arg, int port)
{
  startSocketServer(orchestrator, memberBalances, arg, port);
}

顺便说一句,我开始了一些不同的协作型,平衡和端口线程。请考虑线程安全性也。

BTW, I start a number of threads with different orchestrators, balances and ports. Please consider thread safety also.

推荐答案

尝试使用一个lambda EX pression捕捉到的参数。

Try using a lambda expression to capture the arguments.

Thread standardTCPServerThread = 
  new Thread(
    unused => startSocketServerAsThread(initializeMemberBalance, arg, 60000)
  );
阅读全文

相关推荐

最新文章