I
Ing. Davide Piras
Hi there,
in my c# .NET 2.0 application I run few threads (from 6 to 12 it depends...)
and then my GUI Thread should wait all of them have finished their task...
so after create those threads i put them in a List<>, I start them one by
one then I do something like:
List<Thread> ElencoThreadTabelle = new List<Thread>();
....
....
populate list and starting threads...
....
....
while (ElencoThreadTabelle.Count > 0)
{
if (!ElencoThreadTabelle[0].IsAlive)
{
ElencoThreadTabelle.RemoveAt(0);
}
Application.DoEvents();
Thread.Sleep(250);
}
I don't know this is a good way, I think there should be something better, I
think can use thread.Join() but how to use it (if this is the best way) ?
in my context, any thread executes some works then calls thread.abort() at
the end of the threadProc so my main thread (the GUI) in the snipped above
doesn't need to kill threads, only to wait 'till they are alive then
continue when no one of them is running anymore...
Thanks, Regards, Davide.
in my c# .NET 2.0 application I run few threads (from 6 to 12 it depends...)
and then my GUI Thread should wait all of them have finished their task...
so after create those threads i put them in a List<>, I start them one by
one then I do something like:
List<Thread> ElencoThreadTabelle = new List<Thread>();
....
....
populate list and starting threads...
....
....
while (ElencoThreadTabelle.Count > 0)
{
if (!ElencoThreadTabelle[0].IsAlive)
{
ElencoThreadTabelle.RemoveAt(0);
}
Application.DoEvents();
Thread.Sleep(250);
}
I don't know this is a good way, I think there should be something better, I
think can use thread.Join() but how to use it (if this is the best way) ?
in my context, any thread executes some works then calls thread.abort() at
the end of the threadProc so my main thread (the GUI) in the snipped above
doesn't need to kill threads, only to wait 'till they are alive then
continue when no one of them is running anymore...
Thanks, Regards, Davide.