Пример #1
0
        private void Dispatcher_UnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            if (!Debugger.IsAttached)
            {
                try
                {
                    Settings.Default.WasLastShutdownUnexpected = true;
                    Settings.Default.Save();
                    e.Handled = true;
                    string text = @"
Host Information:
OS: {0},
OSVersion: {1},
Settings: 
{2}
App Location contains invalid characters: {3},
App Version: {4},
========================================================
Exception Information:
Exception was: {5},
Call Stack: {6},
Full Exception Object Dump:
{7}
";

                    text = string.Format(text,
                                         Enum.GetName(typeof(PlatformID), Environment.OSVersion.Platform),
                                         Environment.OSVersion.Version.ToString(),
                                         DumpObject2String(Settings.Default),
                                         Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory).Any(c => c > 127),
                                         VersionChecker.GetCurrentVersion(),
                                         e.Exception.GetType().Name,
                                         e.Exception.StackTrace,
                                         e.Exception.ToString()
                                         );

                    string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "crashinfo-latest.txt");
                    System.IO.File.WriteAllText(path, text);
                    Application.Current.Shutdown(-0x000FFFF); //HRESULT E_UNEXPECTED
                }
                catch
                {
                    throw e.Exception;
                }
            }
        }