小编Leo*_*hev的帖子

无法终止进程:“没有进程与此对象关联”错误

在我的程序中,我尝试启动一个新进程(在默认播放器中打开视频文件)。这部分工作正常。后来,当我尝试关闭进程(播放器)时,出现错误:

System.InvalidOperationException:没有进程与此对象关联。

我的代码:

string filename = "747225775.mp4";
var myProc = new Process()
{
    StartInfo = new ProcessStartInfo(filename)
};
myProc.Start();
Thread.Sleep(5000);
try
{
    myProc.Kill(); //Error is here
}
catch (Exception ex)
{
    Debug.WriteLine(ex);
    Debugger.Break();
}
Run Code Online (Sandbox Code Playgroud)

怎么了?

c# process

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

process ×1