82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
|
|
namespace TouchCashier
|
|
{
|
|
/// <summary>
|
|
/// App.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class App : Application
|
|
{
|
|
System.Threading.Mutex mutex;
|
|
public App()
|
|
{
|
|
DispatcherUnhandledException += App_DispatcherUnhandledException;
|
|
//非UI线程未捕获异常处理事件
|
|
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
|
Startup += new StartupEventHandler(App_Startup);
|
|
}
|
|
|
|
/// <summary>
|
|
/// UI线程异常处理事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
|
{
|
|
//MessageBox.Show(e.Exception.ToString());
|
|
//Shutdown(1);
|
|
try
|
|
{
|
|
LogHelper.WriteServiceLog($"主线程错误:{e.Exception.Message}");
|
|
}
|
|
catch { }
|
|
e.Handled = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 非UI线程异常处理事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
|
{
|
|
//Loger.WriteErrorLog("捕获未处理异常:" + e.ExceptionObject);
|
|
try
|
|
{
|
|
LogHelper.WriteServiceLog("子线程错误:"+(e.ExceptionObject as Exception).Message);
|
|
}
|
|
catch { }
|
|
//MessageBox.Show(e.ExceptionObject.ToString());
|
|
}
|
|
|
|
/// <summary>
|
|
/// 程序启动处理
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
void App_Startup(object sender, StartupEventArgs e)
|
|
{
|
|
bool ret;
|
|
mutex = new System.Threading.Mutex(true, "TouchCashier", out ret);
|
|
if (!ret)
|
|
{
|
|
//ActivateOtherWindow();
|
|
//MessageBox.Show("Program has started, you can't start again!");
|
|
Environment.Exit(0);
|
|
}
|
|
else
|
|
{
|
|
MainWindow _MainWindow = new MainWindow();
|
|
_MainWindow.Show();
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|