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.
 

90 lines
2.7 KiB

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormControl;
namespace Test
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
try
{
//处理未捕获的异常
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
//处理UI线程异常
Application.ThreadException += Application_ThreadException;
//处理非UI线程异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
var aProcessName = Process.GetCurrentProcess().ProcessName;
if ((Process.GetProcessesByName(aProcessName)).GetUpperBound(0) > 0)
{
SoundPalyUtil.PlaySound(SoundType.Error);
UMessageBox.Show(@"系统已经在运行中,如果要重新启动,请从进程中关闭...", @"系统警告");
}
else
{
// Mapper.Initialize(cfg => {
// cfg.AddProfile<AppProfile>();
// cfg.CreateMap<Source, Dest>();
// });
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
}
}
catch (Exception e)
{
// LogUtil.WriteError(e);
SoundPalyUtil.PlaySound(SoundType.Error);
UMessageBox.Show("错误:" + e.Message + " \n详细信息:" + e.StackTrace);
//UMessageBox.Show("错误:" + e.Message );
}
}
///<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);
UMessageBox.Show("错误:" + ex.Message + " \n详细信息:" + ex.StackTrace);
// UMessageBox.Show("错误:" + err);
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var err = String.Empty;
var ex = e.ExceptionObject as Exception;
if (ex != null)
{
//LogUtil.WriteError(ex);
err = ex.Message;
}
SoundPalyUtil.PlaySound(SoundType.Error);
UMessageBox.Show("错误:" + ex.Message + " \n详细信息:" + ex.StackTrace);
//UMessageBox.Show("错误:" + err);
}
}
}