Possible Duplicate:
C# Spawn Multiple Threads for work then wait until all finished
我有两个方法调用,我想使用两个线程调用它们。然后我希望他们等到方法执行完成后再继续。我的示例解决方案如下所示。
public static void Main()
{
Console.WriteLine("Main thread starting.");
String[] strThreads = new String[] { "one", "two" };
String ctemp = string.Empty;
foreach (String c in strThreads)
{
ctemp = c;
Thread thread = new Thread(delegate() { MethodCall(ctemp); });
thread.Start();
thread.Join();
}
Console.WriteLine("Main thread ending.");
Console.Read();
}
public static void MethodCalls(string number)
{
Console.WriteLine("Method call " + number);
}
这会完成这项工作吗?还是有另一种更好的方法来做同样的事情?
我是一名优秀的程序员,十分优秀!