WPF Application Errors and .Net Framework Repairs

后端 未结 5 2107
囚心锁ツ
囚心锁ツ 2021-02-20 10:11

Background: I have a .Net 3.5 WPF \"Prism\"-based application running on Windows XP and Windows PosReady 2009 PCs. The app runs on PCs that are shut down every

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 10:34

    Try a global Error catch and see what it produces.

     public partial class App : Application
        {   
            [STAThread]
            public static void Main()
            {
                    var application = new App();
    
                    application.DispatcherUnhandledException += 
                        new DispatcherUnhandledExceptionEventHandler(application_DispatcherUnhandledException);
    
                    application.InitializeComponent();
                    application.Run();
            }
    
            static void application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
            {
                LogAndClose("Global exception: " + e.Exception.ToString());
            }
    
            public static void Log(string text)
            {
                try
                {
                    System.IO.File.AppendAllText(Environment.CurrentDirectory + "\\Log.txt",
                        "[" + DateTime.Now.ToString("MM/dd/yy HH:mm:ss") + "] " + text + "\r\n");
                }
                catch { }
            }
    
            public static void LogAndClose(string text)
            {
                Log(text);
    
                try
                {
                    Application.Current.Shutdown();
                }
                catch { }
            }
        }
    

提交回复
热议问题