You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

91 lines
2.7 KiB

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using WinFormControl;
namespace ButcherFactory.Login
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App : Application
{
System.Threading.Mutex mutex;
public App()
{
var aProcessName = Process.GetCurrentProcess().ProcessName;
bool ret;
mutex = new System.Threading.Mutex(true, aProcessName, out ret);
if (!ret)
{
SoundPalyUtil.PlaySound(SoundType.Error);
UMessageBox.Show(@"系统已经在运行中,如果要重新启动,请从进程中关闭...", @"系统警告");
Environment.Exit(0);
}
}
protected override void OnStartup(StartupEventArgs e)
{
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetUnhandledExceptionMode(System.Windows.Forms.UnhandledExceptionMode.CatchException);
System.Windows.Forms.Application.ThreadException += Application_ThreadException;
RegisterEvents();
base.OnStartup(e);
}
///<summary>
/// 在发生未处理异常时处理的方法
///</summary>
///<param name="sender"> </param>
///<param name="e"> </param>
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
var ex = e.Exception;
var err = String.Empty;
if (ex != null)
{
//LogUtil.WriteError(ex);
err = ex.Message;
}
SoundPalyUtil.PlaySound(SoundType.Error);
MessageBox.Show("错误:" + ex.Message + " \n详细信息:" + ex.StackTrace);
// UMessageBox.Show("错误:" + err);
}
private void RegisterEvents()
{
DispatcherUnhandledException += App_DispatcherUnhandledException;
TaskScheduler.UnobservedTaskException += (sender, args) =>
{
SoundPalyUtil.PlaySound(SoundType.Error);
MessageBox.Show("错误:" + args.Exception.Message + " \n详细信息:" + args.Exception.StackTrace);
args.SetObserved();
};
AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
{
SoundPalyUtil.PlaySound(SoundType.Error);
MessageBox.Show("Unhandled exception." + args.ExceptionObject);
};
}
void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
SoundPalyUtil.PlaySound(SoundType.Error);
MessageBox.Show("错误:" + e.Exception.Message + " \n详细信息:" + e.Exception.StackTrace);
e.Handled = true;
}
}
}