所谓的潇洒

导航

Winform 进程调用及其退出事件

        System.Threading.SynchronizationContext m_SyncContext = System.Threading.SynchronizationContext.Current;//线程同步

     private void btnCreateDB_Click(object sender, EventArgs e)
        {
            Assembly Asm = Assembly.GetExecutingAssembly();
            string strFile = Asm.Location.Substring(0, (Asm.Location.LastIndexOf("\\") + 1)) + "Test.exe";

            var process = Process.Start(strFile);//启动进程
            process.EnableRaisingEvents = true;
            process.Exited += DbCreateExeExited;//监听进程退出事件
        }

     //进程退出事件处理函数
        private void DbCreateExeExited(object sender, EventArgs e) => m_SyncContext.Post(ReadNewDbConfig, null);
        
     //线程同步处理函数
     private void ReadNewDbConfig(object o)
        {
        textBox1.Text="程序退出";
        }


 


 

posted on 2019-09-11 20:44  所谓的潇洒  阅读(1004)  评论(0编辑  收藏  举报