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;
|
}
|
}
|
|
}
|