I have created threads dynamically.
static void Main(string[] args)
{
int ThreadCount =Convert.ToInt32ConfigurationManager.AppSettings["Threads"]);
List<Thread> th = new List<Thread>();
for (int i = 0; i < ThreadCount; i++)
{
Thread t = new Thread(print);
th.Add(t);
}
foreach (Thread t in th)
{
t.Start();
}
}
public static void print()
{
console.writeline("123");
}
I want to know when this threads will complete.
On completion of these threads I want to print a message of “DONE”
How can I do this.
Thread.Join() could help; see http://msdn.microsoft.com/en-us/library/95hbf2ta.aspx.
You might want to look at the higher level TPL (Task Parallel Library) API; see http://msdn.microsoft.com/en-us/library/dd537609.aspx. It could be easier to use in the long run.
Or in PLINQ , http://msdn.microsoft.com/en-us/library/dd460688.aspx, (haven’t compiled the code)