private void oldquanqd() { apkName = dict["明日方舟"]; int[] yunxingIndex = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; string a_b = "d"; qdinit(a_b); for (int j = 1; j < 1000; j++) { WriteLog.WriteLogFile("", "序号" + j + ",开始"); MyFuncUtil.LaunchAll(yunxingIndex.Length); Thread.Sleep(10000); List <int> newinx = new List <int>(); foreach (int myinx in yunxingIndex) { int i = MyFuncUtil.QiDongWanChengInx(a_b, myinx, apkName); if (i != -1) { newinx.Add(i); } Thread.Sleep(3000); } MyLdcmd.mySort(a_b); Thread.Sleep(2000); ThreadPool.SetMaxThreads(newinx.Count, newinx.Count); //设置最大线程数 foreach (int inx in newinx) { ThreadPool.QueueUserWorkItem(new WaitCallback(duoxiand), inx);//线程池指定线程执行Auto方法 Thread.Sleep(20000); } while (true) { Thread.Sleep(10000);//这句写着,主要是没必要循环那么多次。去掉也可以。 int maxWorkerThreads, workerThreads; int portThreads; ThreadPool.GetMaxThreads(out maxWorkerThreads, out portThreads); ThreadPool.GetAvailableThreads(out workerThreads, out portThreads); if (maxWorkerThreads - workerThreads == 0) { break; } } WriteLog.WriteLogFile("", "序号" + j + ",结束"); } }