未调用流程退出事件处理程序方法 [英] Process Exited event handler method is not being called

查看:54
本文介绍了未调用流程退出事件处理程序方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是下面的代码... Process.Exited 事件处理程序方法没有被调用...我还通过断点和所有这些检查了这一点.

Here is the following code...the Process.Exited event handler method is not being called...I also checked that by breakpoints and all of that.

Process f;

private void button3_Click_1(object sender, EventArgs e)
{
    f = new Process();
    f.StartInfo.FileName = "tutorial.mp4";
    f.EnableRaisingEvents = true;
    f.Exited += new EventHandler(f_Exited);
    f.Start();
}

private void f_Exited(object sender, System.EventArgs e)
{
    //some stuff not important
}

推荐答案

我认为这是不可能的,因为不能保证在打开这样的文件时根本不会启动任何进程.

I think this isn't possible, because it isn't guaranteed that a process is started at all when you open a file like this.

假设没有为文件类型".mp4"设置任何标准程序.然后Windows将要求用户选择一个程序来打开文件.但是,如果用户取消此操作并且根本不选择任何程序,则不会开始任何处理.因此,我认为在这种情况下,因为您不能依赖此事件,所以根本不会触发Exited事件.

Suppose there isn't any standard program set for the file type ".mp4". Then Windows will ask the user to choose a program to open the file; but if the user cancels this and do not choose a program at all, then no process is started. Therfore I believe that in such a case the Exited event isn't fired at all because you can not rely on this.

我能想到的就是直接使用适当的命令行参数启动播放器,如下所示:

All i can think of is to start the player directly with an appropriate command line argument, like so:

Process f;
private void  button3_Click_1(object sender, EventArgs e)
{
    f = new Process();
    f.StartInfo.FileName = "wmplayer.exe"; // or something other
    f.StartInfo.Arguments = @"c:\tutorial.exe"; // as for the wmplayer, you have to specify the whole path.
    f.EnableRaisingEvents = true;
    f.Exited += new EventHandler(f_Exited);
    f.Start();

}
private void f_Exited(object sender, System.EventArgs e)
{
    //some stuff not important
}

这篇关于未调用流程退出事件处理程序方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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