Do you want to determine if thread pool threads are complete?
Using microsoft.visualstudio.testtools.unittesting;using system.collections.generic;using System.Threading;using System.threading.tasks;namespace ex.rulestester.threads{///<summary>///Async wait for all threads to end notification test///</summary& Gt [TestClass] public class Taskallcompletetester {[TestMethod] public void Testtaskpoolstatus () {//Run asynchronous multi-task Tasktest.runtask (); var list = Tasktest.successlist; BOOL Isallcomplete = false; Waits for an asynchronous notification while (!isallcomplete) {isallcomplete = Tasktest.isallcomplete; list = Tasktest.successlist; } assert.istrue (True); }///<summary>//package for Task multitasking//</summary> private class Tasktest {private static object M_lock = new Object (); public static list<string> successlist = new list<string> (); Private static string msg = ""; public static bool Isfinish = FALSE; public static list<task> TaskList = new list<task> (); static bool Isallcomplete = FALSE; <summary>///Mark All tasks complete or not,//</summary> public static bool Isallcompl ete {get {return isallcomplete;} } private Tasktest () {} public static void RunTask () { Run 5 tasks for (int i = 1; I <= 5; i++) {var task = Task.Factory.St Artnew (Dotask, i); Tasklist.add (Task); }//Asynchronously waits for all tasks to complete Task.Factory.StartNew (x = {task.wait All (Tasklist.toarray ()); Mark All Tasks Run complete Isallcomplete = true; }, NULL); } Private STATIC void Dotask (object par) {thread.sleep (int). Parse (par. ToString ()) * 1000); Lock (M_lock) {Successlist.add ("has completed T" + par. ToString ()); } } } }}
Grass Green Studio
Asynchronously monitors whether a thread (task) is fully executed by replacing ThreadPool with a task