Lam*_*fif 3 .net c# windows debugging exception
我想了解Environment.FailFastc#应用程序中的规则.所以,我做了这个代码:
  public static void Main()
   {
       string strInput = GetString();
       Console.WriteLine(strInput);
       Console.ReadKey();
   }
   private static string GetString()
   {
       Console.WriteLine("Get string");
       string s = Console.ReadLine();
       try
       {
           if (s == "Exit")
           {
                Environment.FailFast("Erreur fatale");
                return s;
           }
           else
           {
               return s;
           }
       }
       catch (Exception)
       {
           return "catch";
       }
       finally
       {
           s += "finally";
       }
   }
据我所知,消息被写入,Windows application event log应用程序终止.
当我运行应用程序并将其Exit作为字符串放置时:


我不明白为什么应用程序没有抛出异常而没有关闭?对于第二点,我如何在PC中找到日志文件?
Environment.FailFast(string)立即退出应用程序,不允许catch在对象上运行任何语句或终结器.
如果你的应用程序的状态是在能够一个点时,才应使用此方法永远不会被回收,并退出应用程序,是确保东西远远差于崩溃不会发生的唯一方法.在您的示例中,使用Environment.Exit退出代码更合适,因为它似乎是一个优雅的退出,而不是强制通过腐败状态.
通常,建议在FailFast附加调试器时不要使用- 这在System.Diagnostics.Assert类中有记录:
// However, in CLR v4, Environment.FailFast when a debugger is attached gives you an MDA 
// saying you've hit a bug in the runtime or unsafe managed code, and this is most likely caused 
// by heap corruption or a stack imbalance from COM Interop or P/Invoke.  That extremely
// misleading error isn't right, and we can temporarily work around this by using Environment.Exit 
// if a debugger is attached.  The right fix is to plumb FailFast correctly through our native
// Watson code, adding in a TypeOfReportedError for fatal managed errors.  We may want a contract-
// specific code path as well, using COR_E_CODECONTRACTFAILED.
这意味着您在Visual Studio中看到的异常归结为CLR中的错误,可以安全地忽略.
他们的工作如下:
if (Debugger.IsAttached) 
    Environment.Exit(COR_E_FAILFAST);
else
    Environment.FailFast(message); 
这意味着在附加调试器的情况下运行时,您将无法在发布时获取事件日志消息.