// Handle the UI exceptions by showing a dialog box, and asking the user whether
        // or not they wish to abort execution.
        // NOTE: This exception cannot be kept from terminating the application - it can only
        // log the event, and inform the user about it.
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            try
            {
                Exception ex = (Exception)e.ExceptionObject;
                if (ACRoot.SRoot != null)
                {
                    if (ACRoot.SRoot.Messages != null)
                    {
                        StringBuilder desc       = new StringBuilder();
                        StackTrace    stackTrace = new StackTrace(ex, true);
                        for (int i = 0; i < stackTrace.FrameCount; i++)
                        {
                            StackFrame sf = stackTrace.GetFrame(i);
                            desc.AppendFormat(" Method: {0}", sf.GetMethod());
                            desc.AppendFormat(" File: {0}", sf.GetFileName());
                            desc.AppendFormat(" Line Number: {0}", sf.GetFileLineNumber());
                            desc.AppendLine();
                        }

                        ACRoot.SRoot.Messages.LogException("App.CurrentDomain_UnhandledException", "0", ex.Message);
                        if (ex.InnerException != null && !String.IsNullOrEmpty(ex.InnerException.Message))
                        {
                            ACRoot.SRoot.Messages.LogException("App.CurrentDomain_UnhandledException", "0", ex.InnerException.Message);
                        }

                        string stackDesc = desc.ToString();
                        ACRoot.SRoot.Messages.LogException("App.CurrentDomain_UnhandledException", "Stacktrace", stackDesc);
                    }
                }
            }
            catch (Exception exc)
            {
                try
                {
                    Msg userMsg = new Msg()
                    {
                        Message = "Fatal Non-UI Error. Could not write the error to the event log. Reason: " + exc.Message, MessageLevel = eMsgLevel.Info
                    };
                    VBWindowDialogMsg vbMessagebox = new VBWindowDialogMsg(userMsg, eMsgButton.OK, null);
                    vbMessagebox.ShowMessageBox();
                }
                finally
                {
                    if (ACRoot.SRoot != null)
                    {
                        ACRoot.SRoot.ACDeInit();
                    }
                    // Ist notwendig, damit die Anwendung auch wirklich als Prozess beendet wird
                    App._GlobalApp.Shutdown();
                }
            }
        }
Example #2
0
        private Global.MsgResult ShowMsgBoxIntern(Msg msg, eMsgButton msgButton)
        {
            VBWindowDialogMsg vbMessagebox = new VBWindowDialogMsg(msg, msgButton, this);

            return(vbMessagebox.ShowMessageBox());
        }