I just added a number of (MSIL only) dlls to my project and make calls to methods in it. Now the app randomly crashes, not leaving anything in the logs (stdout, stderr, app logs that are supposed to log all exceptions, and windows app logs) in terms of error messages. There are of course several ways to get to the bottom of this, like grepping for Application.Exit etc. in the (decompiled) sources, but one question that is more general than this narrow problem is this:

What ways are there to exit a .net app using MSIL, in addition to:

  • Application.Exit
  • Environment.Exit
  • Environment.FailFast
  • Process.GetCurrentProcess().Kill
  • Calling anything via [DllImport]
  • new Thread(_ => { throw new Exception(); }).Start() (thanks user626528)
有帮助吗?

解决方案

Your application might be terminated by CLR, if there is an unhandled exception in a background thread. You can use AppDomain.CurrentDomain.UnhandledException to log these events (you can't use it to prevent them from terminating your application, though). You need to put catch blocks to the top functions of all background threads to prevent application termination due to unhandled exceptions.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top