-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathProgram.cs
58 lines (54 loc) · 1.87 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Threading;
using System.Windows.Forms;
namespace Beinet.cn.Tools
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// 对非UI线程异常进行处理,但是无法不退出程序
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm frm;
int tabIndex;
if (args == null || args.Length <= 0 || !int.TryParse(args[0], out tabIndex))
{
frm = new MainForm();
}
else
{
frm = new MainForm(tabIndex);
}
Application.Run(frm);
}
/// <summary>
/// 处理应用程序域内的未处理异常(非UI线程异常)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
Exception ex = e.ExceptionObject as Exception;
var msg = ex?.Message ?? Convert.ToString(e.ExceptionObject);
MessageBox.Show(msg);
}
catch { }
}
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
string message = "出错了:" + e.Exception;
MessageBox.Show(message);
Utility.Log(message, "global");
}
}
}