GC.KeepAlive versus using

后端 未结 3 959
日久生厌
日久生厌 2021-01-01 19:06

In his article about preventing multiple instances of an application, Michael Covington presents this code:

static void Main()                  // args are O         


        
3条回答
  •  悲&欢浪女
    2021-01-01 19:31

    I think the reason KeepAlive is used with the named Mutex is to make sure it IS NOT garbage collected early. The C# using / Dispose pattern is not for protected against that. When an object reference is no longer used within a scope the runtime may collect it before the end of the scope. It's an optimiztion.

提交回复
热议问题