Windows Develop Bookmark and Share   
 index > Windows Forms General > Threads
 

Threads

Hi everyone,
I want to start some threads(e.g 100). then wait for ALL THESE threads to stop then continue working:

function threads()
{
start 100 threads;
wait_to_end();
MessageBox('All Done');
}
thanks.

zoser  Wednesday, September 10, 2008 4:18 PM
Call Thread.Join() 100 times. For example:

using System;
using System.Threading;

namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Thread[] threads = new Thread[100];
for (int ix = 0; ix < threads.Length; ++ix) {
threads[ix] = new Thread(new ParameterizedThreadStart(aThread));
threads[ix].Start(ix+1);
}
foreach (Thread t in threads) t.Join();
Console.WriteLine("done");
Console.ReadLine();
}
static Random mRandom = new Random();
static void aThread(object arg) {
int threadNumber = (int)arg;
Thread.Sleep(mRandom.Next(100, 3000));
Console.WriteLine("Thread #{0} is done", threadNumber);
}
}
}

nobugz  Wednesday, September 10, 2008 4:39 PM
Call Thread.Join() 100 times. For example:

using System;
using System.Threading;

namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Thread[] threads = new Thread[100];
for (int ix = 0; ix < threads.Length; ++ix) {
threads[ix] = new Thread(new ParameterizedThreadStart(aThread));
threads[ix].Start(ix+1);
}
foreach (Thread t in threads) t.Join();
Console.WriteLine("done");
Console.ReadLine();
}
static Random mRandom = new Random();
static void aThread(object arg) {
int threadNumber = (int)arg;
Thread.Sleep(mRandom.Next(100, 3000));
Console.WriteLine("Thread #{0} is done", threadNumber);
}
}
}

nobugz  Wednesday, September 10, 2008 4:39 PM

You can use google to search for other answers

Custom Search

More Threads

• Visual Basic 2008
• MDI Parent and Child form - Close Child
• C# Form2 opened from Form1 does not work, I'm begginer
• using Office Web components(OWC)
• DataGrid and database bound - how then save the new value?
• multiple event handlers for a control in forms designer
• Text entry controls with field masks!
• Font spacing
• Tooltip (Balloontip) problems
• stringBuilder in windows application