Hi All,
I've been look for the solution for this problem for days.. any help is very much appreciated.
My project invovles a small task that requires to generate three concurrent threads, it looks like:
Main()
{
........
//Start three threads;
Start Thread1;
Start Thread2;
Start Thread3;
//Wait for three threads to finish
Thread1.Join();
Thread2.Join();
Thread3.Join()
Messagebox.Show("All threads finished");
......
}
Private void Thread1/2/3 ()
{
//some work here;
}
The code above works.. the only problem is that when the Main was waiting for three threads to finish, all components (eg.buttons) on the Main form were not responding..the Main form was locked...
I am wondering is there anyway to solve this problem?
I tried to use Thread.Sleep along with a While loop to wait:.
Main()
{
........
//Start three threads;
Start Thread1;
Start Thread2;
Start Thread3;
threadFinished = 0;
//Wait for three threads to finish
While (threadFinished <3)
{
Thread.Sleep (5000);
}
Messagebox.Show("All threads finished");
......
}
private void Thread1/2/3 ()
{
//some work here;
lock (this)
{
threadFinished++;
}
}
But it didn't work either..
I want that components on the main form can still work while it's waiting for other threads to finish.
Thanks in advance