一厂MES,含注塑,喷涂,冲孔
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.

114 lines
3.4 KiB

3 months ago
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
3 months ago
using System.Linq;
using System.Text;
3 months ago
using System.Threading.Tasks;
using System.Windows.Forms;
namespace InjectionSearch
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
public static SqlConnection DBConn; //数据库连接串
public static string station;
public static string StationID;
public static string OperatorName;
public static string IP;
public static string Shift; //班次
public static string ProductDate;
[STAThread]
static void Main()
{
bool isRuned;
System.Threading.Mutex mutex = new System.Threading.Mutex(true, "OnlyRunOneInstance", out isRuned);
if (isRuned)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
//处理UI线程异常
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
//处理非UI线程异常
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
3 months ago
Application.Run(new FrmLogin());
mutex.ReleaseMutex();
}
else
{
MessageBox.Show("程序已启动!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
#region 系统异常处理
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
string str = GetExceptionMsg(e.Exception, e.ToString());
MessageBox.Show(str);
//LogManager.WriteLog(str);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string str = GetExceptionMsg(e.ExceptionObject as Exception, e.ToString());
MessageBox.Show(str);
//LogManager.WriteLog(str);
}
static string GetExceptionMsg(Exception ex, string backStr)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("****************************异常文本****************************");
sb.AppendLine("【出现时间】:" + DateTime.Now.ToString());
if (ex != null)
{
sb.AppendLine("【异常类型】:" + ex.GetType().Name);
sb.AppendLine("【异常信息】:" + ex.Message);
sb.AppendLine("【堆栈调用】:" + ex.StackTrace);
}
else
{
sb.AppendLine("【未处理异常】:" + backStr);
}
sb.AppendLine("***************************************************************");
return sb.ToString();
}
private static void ExceptionMonitor_ExceptionOver()
{
MessageBox.Show("系统遇到未知异常,即将重新启动。");
Process.Start(Application.ExecutablePath);
Process.GetCurrentProcess().Kill();
}
#endregion
3 months ago
}
}