zoukankan      html  css  js  c++  java
  • 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");
            }
        }
  • 相关阅读:
    积性函数前缀和
    CF1067D Computer Game
    Atcoder Tenka1 Programmer Contest 2019 题解
    Codeforces Round #549 (Div. 1) 题解
    SHOI2019旅游记
    CF871D Paths
    CF1065E Side Transmutations
    停更公告
    博客说明
    SCOI2019酱油记
  • 原文地址:https://www.cnblogs.com/xietianjiao/p/15414177.html
Copyright © 2011-2022 走看看