更新
我有一个与Process.Start();
相关的问题。我的程序启动文件作为进程,如下所示:
Process processMonitor = new Process();
processMonitor.StartInfo.FileName = filePath; // Example: @"C:\test.txt"
processMonitor.StartInfo.CreateNoWindow = true;
processMonitor.Exited += new EventHandler(Process_Exited);
processMonitor.EnableRaisingEvents = true;
processMonitor.Start();
// Handle Exited event and display process information.
private void Process_Exited(object sender, EventArgs e)
{
// This code is called on every exit, except images: (Windows Photo Viewer, *jpg, *png, *bmp etc.)
}
这可以成功启动一个进程,notepad.exe并打开正确的文件。捕获Exited事件也有效,所以基本上我已经准备好监视进程的关闭事件了。
现在来看问题...
当尝试做同样的事情,但是针对的是一张图片时:
processMonitor.StartInfo.FileName = filePath; // Example: @"C:\test.jpg"
这不成功。进程启动得很好,但是我无法检测到进程是否已关闭。一些研究显示一个名为:
DLLHOST.EXE(COM Surrogate)
被启动,并且我无法检测到此进程的Exited事件。
有人可以帮助我吗?或者至少指引我正确的方向?
Start("http://www.google.com")
返回的Process
(打开默认浏览器,我的系统上是Google Chrome)是null
?我想要获取它的MainWindowHandle
,但因为它是null
,所以我无法对它进行任何操作(在启动后)。 - King King