I need to use clear thread class (not Task and without async/await). How I can correctly wait of the ends of all task in list?
I want correctly method WaitAll()
For example:
public class TaskManager
{
private readonly List<Thread> _threads = new List<Thread>();
public void AddTask([NotNull] Action<int> action, int i)
{
var thread = new Thread(() =>
{
action(i);
});
_threads.Add(thread);
thread.Start();
}
public void WaitAll()
{
while (_threads.Any(x => x.ThreadState != ThreadState.Stopped))
{
}
}
}