System.Diagnostics.Process.Start().如何停止泄漏手柄? [英] System.Diagnostics.Process.Start(). How do I stop leaking handles?

查看:70
本文介绍了System.Diagnostics.Process.Start().如何停止泄漏手柄?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Process.Start()启动可执行文件,然后使用CloseMainWindow将其关闭.它工作得很好,但是当我使用winXP Performance Monitor来跟踪应用程序的句柄使用时,每次调用进程开始/停止周期时都会使用完句柄.这些句柄没有关闭.如何确保我不会泄漏资源?

I am launching an executable using Process.Start() and then closing it with CloseMainWindow.  It works quite well, but when I use the winXP Performance Monitor I to track handle usage by the application am using up handles with each invocation of the process start/stop cycle.  These handles are not being closed.  How do I ensure I don't leak resources?

我已经测试了以下代码作为该问题的简化版本(使用Win2K计算器应用程序),并且可以验证其是否具有相同的行为.

I have tested the following code as a reduced version of the problem (using the Win2K calculator application) and can verify it has the same behaviour.

谁能看到我在做什么错

tia.

私有 无效 RunTheCalculator(){

private void RunTheCalculator() {

使用(System.Diagnostics. Process calcProcess =

  using (System.Diagnostics.Process calcProcess = new

System.Diagnostics.流程 {

calcProcess.StartInfo.FileName =

     calcProcess.StartInfo.FileName =

"C:\\ WINDOWS \\ system32 \\ calc.exe" ;

        "C:\\WINDOWS\\system32\\calc.exe";

calcProcess.StartInfo.WorkingDirectory =

" C:\\ WINDOWS \\ system32" ;

       "C:\\WINDOWS\\system32";

calcProcess.StartInfo.UseShellExecute = true ;

     calcProcess.StartInfo.UseShellExecute = true;

如果 (calcProcess.Start ()) {

尝试{

如果 (calcProcess.WaitForInputIdle(10000)) {

////做我们的事情...

//关闭商店...

calcProcess.CloseMainWindow();

calcProcess.WaitForExit(10000);

.

>} {

///在我们处理时应该是多余的,但是...

calcProcess.Close();

.

.

}

}

推荐答案

我认为我的应用程序存在相同的问题.当我使用Process.Start()启动它时,句柄急剧增加,但是当我直接启动它时,一切都很好.

I think I have the same problem with my application. When I start it whith Process.Start(), handles increase dramaticaly, but when I start it directly, all is good.


这篇关于System.Diagnostics.Process.Start().如何停止泄漏手柄?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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