代码之家  ›  专栏  ›  技术社区  ›  zerkms

最后:是否保证在任何情况下都可以调用它?

  •  3
  • zerkms  · 技术社区  · 14 年前

    有没有可能 finally 将不会被调用,但应用程序仍在运行?

    我在那里释放信号灯

            finally
            {
                _semParallelUpdates.Release();
            }
    

    害怕失去其中一些。

    6 回复  |  直到 13 年前
        2
  •  1
  •   Steven    14 年前
        3
  •  0
  •   this. __curious_geek    14 年前

    finally

        4
  •  0
  •   Heinzi    14 年前

    this was possible finally Thread.Abort

        5
  •  0
  •   Dan Tao    14 年前

    finally

    IDisposable someDisposableObject = null;
    IDisposable someOtherDisposableObject = null;
    
    try
    {
        someDisposableObject = GetDisposableObject();
    
        throw new Exception("Holy crap, something bad happened.");
    
        someOtherDisposableObject = GetOtherDisposableObject();
    }
    finally
    {
        // This will throw a NullReferenceException...
        someOtherDisposableObject.Dispose();
    
        // ...so this actually won't run.
        someDisposableObject.Dispose();
    }
    

        6
  •  0
  •   supercat    13 年前