In WinForms, I use:
- System.Windows.Forms.Application.ThreadException
- System.Windows.Application.UnhandledException
What should I use for a multi-threaded application without Winforms?
Consider the full code below in C # .NET 4.0:
using System; using System.Threading.Tasks; namespace ExceptionFun { class Program { static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Task.Factory.StartNew(() => { throw new Exception("Oops, someone forgot to add a try/catch block"); }); } static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) {
I saw many similar questions in stackoverflow, but none of them contained a satisfactory answer. Most answers are of the type: "You must include the correct exeption handling in your code" or "Use AppDomain.CurrentDomain.UnhandledException".
Edit: it looks like my question was misinterpreted, so I reformulated it and presented an example of smaller code.
Eiver source share