垃圾收集问题。 [英] Problems with Garbage Collection.

查看:78
本文介绍了垃圾收集问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个启动流程的课程(除此之外)。我保持

跟踪进程句柄,并且在被垃圾收集器销毁的对象之前,我想杀死该进程。基本上,如果有一些

退出我的应用程序,我不想要任何流浪的后台应用程序

由我的班级实例创建。


我尝试在类'

析构函数中的进程句柄上调用kill()方法,但是句柄必须已经被销毁,因为它不是

再次有效处理(即使你现在孤立的进程仍然是运行的
)。


我怎样才能实现我想要的目标做?有没有办法在之前的垃圾收集中捕获一个偶数




你可能已经猜到了,我对这个C#的东西很新。 :-)


感谢您的任何建议...

I have a class that launches a process (amongst other things). I keep
track of the process handle, and just prior to the obejct being destroyed
by the garbage collector, I want to kill that process. Basically, if some
exits my application, I don''t want any stray background applications
running created by instances of my class.

I tried calling the kill() method on the process handle in the class''s
destructor, but the handle must have been destroyed already, as it''s not a
valid handle any more (even thou the now orphaned process is still
running).

How can I achieve what I want to do? Is there a way of trapping a even
just prior ro garbage colection?

As you may have guessed, I am quite new to this C# stuff.. :-)

Thanks for any suggestions...

推荐答案

因为您无法控制何时垃圾收集被调用,这个

不是正确的方法。相反,你需要在你的程序中有一个

的methedology,以确保执行所有必需的

清理。

As you have no control over when garbage collection gets called, this
is not the proper way to do this. Instead you need to have a
methedology inside your program to make sure that all the needed
cleanup is performed.


只是一个想法,它可能是错的 - 但你是否考虑制作处理静态的

,然后在你的
$ b中的Application.ApplicationExit上$ b主要尝试摧毁它吗?
just a thought, and it''s probably wrong - but did you look into making
that handle static, and then on Application.ApplicationExit within your
Main try destroying it?


On Sun,2005年10月9日16:39:38 +0100,william_dudek @ _yahoo_com

< wi ***********@yahoo.com>写道:
On Sun, 09 Oct 2005 16:39:38 +0100, william_dudek@_yahoo_com
<wi***********@yahoo.com> wrote:
由于你无法控制何时调用垃圾收集,这个
不是正确的方法。相反,你需要在你的程序中有一个
methedology来确保执行所有需要的清理工作。
As you have no control over when garbage collection gets called, this
is not the proper way to do this. Instead you need to have a
methedology inside your program to make sure that all the needed
cleanup is performed.



喜欢应用程序关闭,而不是删除对象?

的任何例子我应该怎么考虑这样做?


Like on application close, rather than object deletion? Any examples of
how I should consider doing this?


这篇关于垃圾收集问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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