asmrobot
2019-10-29 f25f89101a98ad815c0ae2d25e1a8dc35d53a5dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using RichCreator.Models;
using ZTImage.Configuration;
using ZTImage.Log;
 
namespace RichCreator
{
    public class Startup
    {
        private static App app; //这才是真正的Application
 
        [STAThread]
        public static void Main(string[] args)
        {
            if (!G.Instance.ApplicationEntry())
            {
                MessageBox.Show("应用程序已经运行请不要重复运行");
                Application.Current.Shutdown(0);
                return;
            }
 
            Trace.EnableListener(ZTImage.Log.NLog.Instance);            
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
 
            app = new App();
            app.InitializeComponent();
            app.Run();
        }
 
 
 
 
 
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;
            Trace.Error("未处理的异常", ex);
        }
        
    }
 
 
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            this.DispatcherUnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
            this.Exit += App_Exit;
        }
 
        private void App_Exit(object sender, ExitEventArgs e)
        {
            G.Instance.Release();
        }
 
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            //设为对话框关闭程序关闭
            Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
            Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "yyyy-MM-dd";
 
 
            MainWindow mainwindow = new MainWindow();
            Current.ShutdownMode = ShutdownMode.OnMainWindowClose;
            Current.MainWindow = mainwindow;
            mainwindow.Show();
        }
        void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            Trace.Error("Dispatcher未处理的异常", e.Exception);
            e.Handled = true;
        }
    }
    
}