将实例方法传递给线程

时间:2013-03-13 05:15:13

标签: c# multithreading methods instance

我想同时从另一个类运行两个方法。显然,下面的代码不起作用。我怎么能这样做?

Node node = new Node();
EHNode ehnode = new EHNode();

Thread normalNode = new Thread(node.RunNode());
Thread ehNode = new Thread(ehnode.RunNode());

normalNode.Start();
ehNode.Start();

1 个答案:

答案 0 :(得分:1)

这会有所帮助:

Node node = new Node();
EHNode ehnode = new EHNode();

Thread normalNode = new Thread(new ThreadStart(node.RunNode));
Thread ehNode = new Thread(new ThreadStart(ehnode.RunNode));

normalNode.Start();
ehNode.Start();