Calling Environment.Exit() Within a Using Block

后端 未结 2 537
梦毁少年i
梦毁少年i 2021-01-11 14:16

If I have a console application with code like:

using (DisposableObject object = new DisposableObject())
{
   if (a condition)
     Environment.Exit(0);

            


        
2条回答
  •  独厮守ぢ
    2021-01-11 15:21

    Your application will terminate and all managed memory will be released at that point.

    The generated finally block will not execute, so any Dispose methods will not be called, so any non-managed resources may very well not be released.

    See Don't Blindly Count on a Finalizer.

提交回复
热议问题