异步+Timer调用

来源:互联网 发布:网络直播歌手排名 编辑:程序博客网 时间:2024/05/01 16:31

        BAL.Process CIprocess = new BAL.Process();

        delegate void dgProcess(string processName);
        private dgProcess dgP = null;
        private DAL.tbProcessName tbProcessName = new DAL.tbProcessName();
        private System.Diagnostics.Process[] process;

        public ComputerInformation()
        {
            InitializeComponent();

            System.Timers.Timer t = new System.Timers.Timer(60000);//60秒计时
            t.Elapsed +=new System.Timers.ElapsedEventHandler(t_Elapsed);
            t.AutoReset = true;
            t.Enabled = true;//启用Elapsed 
        }

 

 

        void test(string strProcess)
        {
            BAL.Process balProcess = new BAL.Process();
            balProcess.ProcessInfo(process, strProcess);
        }

        //回调
        private void CallBackMethod(IAsyncResult ar)
        {
            dgProcess dn = (dgProcess)ar.AsyncState;
            dn.EndInvoke(ar);
        }

       
        private void t_Elapsed(object sender, EventArgs e)
        {
            process = System.Diagnostics.Process.GetProcesses();
            IAsyncResult iar;
            string[] ss = tbProcessName.ProcessName();
            for (int i = 0; i < ss.Length; i++)
            {
                dgP = new dgProcess(test);
                AsyncCallback acb = new AsyncCallback(CallBackMethod);
                iar = dgP.BeginInvoke(ss[i], acb, dgP);
            }
        }

原创粉丝点击