如何使用GC.KeepAlive()以及用于什么目的? [英] How to use GC.KeepAlive() and for what purpose?
问题描述
我们如何使用 GC.KeepAlive()
目的是什么?
How can we use GC.KeepAlive()
and what is the purpose?
我使用套接字将文件从终端(Windows-CE)传输到服务器.传输所需时间为8分钟. 5分钟后,Windows-CE关闭(如果未按触摸屏)
I transfer files from terminal (Windows-CE) to Server using Socket. The time needed for transfer is 8 minutes. After 5 minutes the Windows-CE shuts down (if touch screen not pressed)
如果我为此使用GC.KeepAlive()
,是否可以解决我的问题?
If I use GC.KeepAlive()
for this, does this solve my problem?
推荐答案
您很少需要使用GC.KeepAlive
-非常.例如,如果您想防止终结器的副作用过早发生,则可以使用它.我最经常看到它用于 Mutex
-保持互斥锁处于活动状态,直到应用程序结束为止,以确保只有一个实例. (在这里using
语句实际上更好,但这是另一回事.)
You very rarely need to use GC.KeepAlive
- very rarely. You'd use it if you wanted to prevent the side-effect of a finalizer from occurring too early, for example. I've most often seen it used for Mutex
- keeping mutex alive until the end of an app to make sure there's only one instance. (A using
statement is actually better here, but that's a separate matter.)
不,这听起来与您的情况无关.
And no, it doesn't sound like it's relevant in your situation.
这篇关于如何使用GC.KeepAlive()以及用于什么目的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!