1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Threading;
- using System.Diagnostics;
- namespace LYFZ.ManagementService
- {
- static class Program
- {
- /// <summary>
- /// 应用程序的主入口点。
- /// </summary>
- [STAThread]
- static void Main()
- {
- Application.EnableVisualStyles();
- Application.SetCompatibleTextRenderingDefault(false);
- //处理未捕获的异常
- Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
- //处理UI线程异常
- Application.ThreadException += Application_ThreadException;
- //处理非UI线程异常
- AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
- bool create;
- using (Mutex mu = new Mutex(true, Application.ProductName, out create))
- {
- if (create)
- {
- Application.Run(new frmMain());
- }
- else
- {
- MessageBox.Show("程序已经在运行!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- Application.Exit();
- return;
- }
- }
- }
- static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
- {
- Exception myException = (Exception)e.ExceptionObject;
- try
- {
- LYFZ.ComponentLibrary.frmExceptionError frmError = new ComponentLibrary.frmExceptionError();
- frmError.Text = "未捕获的错误";
- frmError.ErrorTypeName = "[" + frmError.Text + "]" + myException.GetType().Name;
- frmError.ErrorMessage = myException.Message;
- frmError.ErrorStackTrace = myException.StackTrace.ToString();
- frmError.ShowDialog();
- errorWriteSystemLog(frmError.txtErrorInfo.Text);
- }
- catch
- {
- MessageBox.Show("未被捕获的异常错误,\r\n错误原因:" + myException.Message);
- }
- // Application.ExitThread();
- // Application.Exit();
- }
- static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
- {
- try
- {
- Exception myException = e.Exception;
- LYFZ.ComponentLibrary.frmExceptionError frmError = new ComponentLibrary.frmExceptionError();
- frmError.Text = "未捕获的UI线程错误";
- frmError.ErrorTypeName = "[" + frmError.Text + "]" + myException.GetType().Name;
- frmError.ErrorMessage = myException.Message;
- frmError.ErrorStackTrace = myException.StackTrace.ToString();
- frmError.ShowDialog();
- errorWriteSystemLog(frmError.txtErrorInfo.Text);
- }
- catch
- {
- MessageBox.Show("未捕获的线程异常错误,\r\n错误原因:" + e.Exception.Message.ToString());
- }
- }
- static void errorWriteSystemLog(string errorMsg)
- {
- try
- {
- LYFZ.DAL.DAL_FileLogs.WriteMainLogs("程序错误日志:" + errorMsg);
- }
- catch { }
- }
- }
- }
|