线程与多参数

扫码查看
本文介绍了线程与多参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何将多个参数传递到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)
  );

这篇关于线程与多参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 10:58
查看更多