C#检测进程退出 [英] C# detect process exit

查看:398
本文介绍了C#检测进程退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下code:

   private void fileSystemWatcher_Changed(object sender, System.IO.FileSystemEventArgs e)
    {
        System.Diagnostics.Process execute = new System.Diagnostics.Process();

        execute.StartInfo.FileName = e.FullPath;
        execute.Start();

        //Process now started, detect exit here

    }

在FileSystemWatcher的是看哪里的.exe文件都得到保存到一个文件夹中。这得到了保存到该文件夹​​中的文件被正确执行。但打开exe文件关闭时,另一功能应该被触发。

The FileSystemWatcher is watching a folder where .exe files are getting saved into. The files which got saved into that folder are executed correctly. But when the opened exe closes another function should be triggered.

有没有一种简单的方法来做到这一点?

Is there a simple way to do that?

推荐答案

过程。 WaitForExit

顺便一提,因为进程工具的IDisposable ,你真正想要的:

And incidentally, since Process implements IDisposable, you really want:

using (System.Diagnostics.Process execute = new System.Diagnostics.Process())
{
    execute.StartInfo.FileName = e.FullPath; 
    execute.Start(); 

    //Process now started, detect exit here 
}

这篇关于C#检测进程退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆