我可以阻止垃圾收集器停止一些线程吗? [英] Can I prevent garbage collector from stopping some of my threads?

查看:118
本文介绍了我可以阻止垃圾收集器停止一些线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Compact Framework应用程序中阻止垃圾回收器无条件停止至少一个线程,或至少在代码的某些部分阻止GC收集?



我认为它必须处理设置实时优先级,但是我发现很多建议不这样做。 解决方案

GC需要冻结所有线程才能检查所有对象。如果某个线程正在运行并且正在修改/创建一个对象,它如何完成它的工作?



最好不要这样做。



您可以执行的操作是在您不希望中断的状态下调用GC.Collect()和GC.WaitForPendingFinalizers()。这会给你一些时间。


Is it possible in a Compact Framework application to prevent the garbage collector from unconditionally stopping at least one of the threads, or to block GC collects at least in some portions of the code?

I think it has to deal with setting real time priorities, but I found a lot of advice against doing it.

解决方案

The GC needs to freeze all threads in order to inspect all objects. How could it do its job, if some thread is running and is modifying/creating an object?

Better don't do it.

What you can do thogh, is to invoke GC.Collect() and GC.WaitForPendingFinalizers() before you enter in a state where you do not want to be interrupted. This will give you some time.

这篇关于我可以阻止垃圾收集器停止一些线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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