GC.KeepAlive()取消注释时,仍然只有一个实例,怎么办? [英] GC.KeepAlive() when this is uncommented, still there is only one instance, how ?

查看:79
本文介绍了GC.KeepAlive()取消注释时,仍然只有一个实例,怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的参考线程上,即使我注释了GC.KeepAlive(),我也没有发现任何区别,它阻止了任何其他实例的创建。作者为什么明确提到它的重要方面?

On against to the reference thread below, even if I comment the GC.KeepAlive() there is no difference I find and it blocks the creation of any other instance. Why is it the author explicitly mentioned its important line ?

仅确保一个应用程序实例

推荐答案

如果不这样做,互斥体将在垃圾回收时被销毁,但这不是保证的事件立即发生,这就是为什么它仍然可以长时间工作的原因。

If you don't do this the mutex will be destroyed on garbage collection but this isn't a guaranteed event to happen instantly that's why it can still work for a long time.

我本来会用一个静态的自我来查看第二个答案。

I would have used a static my self see the second answer.

这篇关于GC.KeepAlive()取消注释时,仍然只有一个实例,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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