Please help. Creating threads and wait till finsh
Posted
by Raj Aththanayake
on Stack Overflow
See other posts from Stack Overflow
or by Raj Aththanayake
Published on 2010-04-22T04:32:53Z
Indexed on
2010/04/22
4:43 UTC
Read the original article
Hit count: 432
multithreading
Hi I have two method calls that I want to call using two threads. Then I want them to wait till method executions get completed before continuing. My sample solution is something like below.
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);
}
Is this will do the job? Or is there another better way to do the same thing?
© Stack Overflow or respective owner