Ejemplo n.º 1
0
        private static void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            if (e.Handled == false)
            {
                if (e.Exception.GetType() == typeof(NotImplementedException))
                {
                    e.Handled = true;
                    NotImplementedException?.Invoke(sender, e);
                    return;
                }

                try
                {
                    if (e.Handled)
                    {
                        return;
                    }
                    System.Management.ManagementClass mc =
                        new System.Management.ManagementClass("Win32_OperatingSystem");
                    System.Management.ManagementObjectCollection moc = mc.GetInstances();
                    foreach (System.Management.ManagementObject mo in moc)
                    {
                        ExceptionInformation.OSName        = mo["Name"].ToString();
                        ExceptionInformation.OSVersion     = mo["Version"].ToString();
                        ExceptionInformation.OSLocale      = mo["Locale"].ToString();
                        ExceptionInformation.OSLanguage    = mo["OSLanguage"].ToString();
                        ExceptionInformation.OSBuildNumber = mo["BuildNumber"].ToString();

                        int.TryParse(mo["TotalVisibleMemorySize"].ToString(), out ExceptionInformation.TotalVisibleMemorySize);
                        int.TryParse(mo["FreePhysicalMemory"].ToString(), out ExceptionInformation.FreePhysicalMemory);
                        int.TryParse(mo["TotalVirtualMemorySize"].ToString(), out ExceptionInformation.TotalVisibleMemorySize);
                        int.TryParse(mo["FreeVirtualMemory"].ToString(), out ExceptionInformation.FreeVirtualMemorySize);
                        int.TryParse(mo["FreeSpaceInPagingFiles"].ToString(), out ExceptionInformation.FreeSpaceInPagingFiles);
                        int.TryParse(mo["SizeStoredInPagingFiles"].ToString(), out ExceptionInformation.SizeStoredInPagingFiles);
                        object o = mo["TotalSwapSpaceSize"];
                        if (o != null)
                        {
                            int.TryParse(o.ToString(), out ExceptionInformation.TotalSwapSpaceSize);
                        }

                        mo.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    ExceptionInformation.Message += "Failed to get some informations.\r\n" + ex.ToString();
                }

                ExceptionInformation.Exception = e.Exception;
                ExceptionInformation.Handled   = e.Handled;
                ExceptionInformation.Log       = Dialogs.LogWindow.LogStr;

                Dialogs.UnhandledExceptionDialog dlg = new Dialogs.UnhandledExceptionDialog();
                dlg.ErrorMsg.Text = ExceptionInformation.ToString();
                dlg.ShowDialog();
                if (dlg.ExitApp)
                {
                    Process.GetCurrentProcess().Kill();
                }
                else
                {
                    e.Handled = true;
                }
            }
        }