private static void OnError(object sender, ThreadExceptionEventArgs e) { Trace.WriteLine(e.Exception, "TransferringService: ERR"); ClientDataAccess.InsertMessageAsync(e.Exception.Message, eSources.TransferringService, eMessageTypes.Error, e.Exception.StackTrace); }
public static void OnError(object sender, ThreadExceptionEventArgs e) { //Every exception is recordered but only application predefined //exceptions are shown in this scope Exception ex = e.Exception; //The exception comes from the ThreadPool dynamic Invoker. //The real exception is wrapped into it. Get it. if (ex is TargetInvocationException && ex.InnerException != null) { ex = ex.InnerException; } if (ex is ThreadAbortException || ex is ThreadInterruptedException) { return; } MessageBoxIcon icon = MessageBoxIcon.Error; if (e.Exception is AppInfoException) { icon = MessageBoxIcon.Information; } else if (ex is AppWarningException) { icon = MessageBoxIcon.Warning; } else if (ex is AppExclamationException) { icon = MessageBoxIcon.Exclamation; } else if (ex is AppStopException) { icon = MessageBoxIcon.Stop; } if (!(ex is ApplicationException)) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, icon); } //TODO: eMessageTypes.Error should be described more precisely ClientDataAccess.InsertMessageAsync(ex.Message, eSources.VScan, eMessageTypes.Error, ex.StackTrace); Delegate nextDelegate = ex.GetNext(); if (nextDelegate != null && nextDelegate != default(Delegate)) { nextDelegate.FireAndForget(); } if (ex is AppStopException || ex is SecurityException) { Environment.Exit(10); } }