Aug 05, 2020 03:40 PM|bruce (sqlwork.com)|LINK
but in this code, you create a thread for each task, then use Task.Run() to create (even though its pooled) another thread to run the code. You should do one or the other.
Task.Run() is just a thread manager. It uses real threads, i just has a pool. This allows to control the max threads, and reuse.
the problem with the original code, is the program was exiting before threads could complete. while thread wait is better, you could do Console.Read().
the proper way is after
// start threads
Thread CallTask1 = new Thread(Task1);
Thread CallTask2 = new Thread(Task2);
Thread CallTask3 = new Thread(Task3);
Thread CallTask4 = new Thread(Task4);
Thread CallTask5 = new Thread(Task5);
Thread CallTask6 = new Thread(Task6);
Thread CallTask7 = new Thread(Task7);
Thread CallTask8 = new Thread(Task8);
Thread CallTask9 = new Thread(Task9);
Thread CallTask10 = new Thread(Task10);
// wait completion (could put threads in an array or use a sync counter)