【问题标题】:A curious bit of C# code - needs some explaining [duplicate]一段奇怪的 C# 代码 - 需要一些解释 [重复]
【发布时间】:2011-03-07 21:28:03
【问题描述】:

可能重复:
Why use try {} finally {} with an empty try block?

在浏览 MS .NET 代码时,我偶然发现了这篇文章:

try { } finally 
{
  // Called in a finally because it needs to run uninterrupted in order to maintain consistency.
  queued = IOThreadScheduler.current.ScheduleCallbackHelper(callback, state);
}

有趣的把戏。谁能给个解释?

【问题讨论】:

    标签: c#


    【解决方案1】:

    这很可能是为了在存在ThreadAbortException 的情况下执行该行。

    根据docs

    当引发此异常时,运行时会在结束线程之前执行所有 finally 块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 2015-03-18
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 2014-11-14
      相关资源
      最近更新 更多