コード例 #1
0
        /// <summary>
        ///   Raise Exception Dialog box for both UI and non-UI Unhandled Exceptions
        /// </summary>
        /// <param name = "e">Catched exception</param>
        private void ShowUnhandledExceptionDlg(Exception e)
        {
            Exception unhandledException = e;

            if (unhandledException == null)
            {
                unhandledException = new Exception("Unknown unhandled Exception was occurred!");
            }

            var exDlgForm = new UnhandledExDlgForm();

            try
            {
                string appName = Process.GetCurrentProcess().ProcessName;
                exDlgForm.Text                    = RandomString(8, true);
                exDlgForm.labelTitle.Text         = String.Format(exDlgForm.labelTitle.Text, appName);
                exDlgForm.checkBoxRestart.Text    = String.Format(exDlgForm.checkBoxRestart.Text, appName);
                exDlgForm.checkBoxRestart.Checked = RestartApp;

                // Disable the Button if OnSendExceptionClick event is not handled
                exDlgForm.buttonSend.Enabled = (OnSendExceptionClick != null);

                // Attach reflection to checkbox checked status
                exDlgForm.checkBoxRestart.CheckedChanged += delegate { _dorestart = exDlgForm.checkBoxRestart.Checked; };

                exDlgForm.textBox1.AppendText("Message: " + unhandledException.Message + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Inner exception: " + unhandledException.InnerException +
                                              Environment.NewLine);
                exDlgForm.textBox1.AppendText("Source: " + unhandledException.Source + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Stack trace: " + unhandledException.StackTrace + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Target site: " + unhandledException.TargetSite + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Data: " + unhandledException.Data + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Link: " + unhandledException.HelpLink + Environment.NewLine);

                // Show the Dialog box:
                bool sendDetails = (exDlgForm.ShowDialog() == DialogResult.Yes);

                if (OnSendExceptionClick != null)
                {
                    var ar = new SendExceptionClickEventArgs(sendDetails, unhandledException, _dorestart);
                    OnSendExceptionClick(this, ar);
                }
            }
            finally
            {
                exDlgForm.Dispose();
            }
            Environment.Exit(0);
        }
コード例 #2
0
        /// <summary>
        ///   Raise Exception Dialog box for both UI and non-UI Unhandled Exceptions
        /// </summary>
        /// <param name = "e">Catched exception</param>
        private void ShowUnhandledExceptionDlg(Exception e)
        {
            Exception unhandledException = e;

            if (unhandledException == null)
                unhandledException = new Exception("Unknown unhandled Exception was occurred!");

            var exDlgForm = new UnhandledExDlgForm();
            try
            {
                string appName = Process.GetCurrentProcess().ProcessName;
                exDlgForm.Text = RandomString(8, true);
                exDlgForm.labelTitle.Text = String.Format(exDlgForm.labelTitle.Text, appName);
                exDlgForm.checkBoxRestart.Text = String.Format(exDlgForm.checkBoxRestart.Text, appName);
                exDlgForm.checkBoxRestart.Checked = RestartApp;

                // Disable the Button if OnSendExceptionClick event is not handled
                exDlgForm.buttonSend.Enabled = (OnSendExceptionClick != null);

                // Attach reflection to checkbox checked status
                exDlgForm.checkBoxRestart.CheckedChanged += delegate { _dorestart = exDlgForm.checkBoxRestart.Checked; };

                exDlgForm.textBox1.AppendText("Message: " + unhandledException.Message + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Inner exception: " + unhandledException.InnerException +
                                              Environment.NewLine);
                exDlgForm.textBox1.AppendText("Source: " + unhandledException.Source + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Stack trace: " + unhandledException.StackTrace + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Target site: " + unhandledException.TargetSite + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Data: " + unhandledException.Data + Environment.NewLine);
                exDlgForm.textBox1.AppendText("Link: " + unhandledException.HelpLink + Environment.NewLine);

                // Show the Dialog box:
                bool sendDetails = (exDlgForm.ShowDialog() == DialogResult.Yes);

                if (OnSendExceptionClick != null)
                {
                    var ar = new SendExceptionClickEventArgs(sendDetails, unhandledException, _dorestart);
                    OnSendExceptionClick(this, ar);
                }
            }
            finally
            {
                exDlgForm.Dispose();
            }
            Environment.Exit(0);
        }