C#线程调度のManualResetEvent集合
等待所有子线程执行完毕
class StopAllWaitBySubThread { List manualEvents = new List(); public void Main() { ManualResetEvent mre = new ManualResetEvent(false); manualEvents.Add(mre); ThreadPool.QueueUserWorkItem(ThreadMethod, mre); Form f = Application.OpenForms["Form_CreateObject"];//查找是否打开过窗体 if (f == null) //没打开过 ,打开 { Form_CreateObject datamanage = new Form_CreateObject(); datamanage.Show(); } else { f.Focus(); //打开过就让其获得焦点 } WaitHandle.WaitAll(manualEvents.ToArray());//程序会在此处暂停,等待子线程运行结束。 f = Application.OpenForms["Form_CreateObject"];//查找是否打开过窗体 if (f == null) //没打开过 { } else { f.Close(); //打开过就关掉 } } private void ThreadMethod(object obj) { //耗时的函数,处理事情,Matlab Matlab(); ManualResetEvent mre = (ManualResetEvent)obj; mre.Set(); Console.WriteLine("Thread execute"); } }