代码拉取完成,页面将自动刷新
using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace HaiFeng
{
static class Program
{
private static string _errLog = string.Empty;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
_errLog = "err_" + Application.ProductName + ".log";
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//你在主线程捕获全部异常就行,如下代码:
//WINFORM未处理异常之捕获
//处理未捕获的异常
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
//处理UI线程异常
Application.ThreadException += Application_ThreadException;
//处理非UI线程异常
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
Application.Run(new HFForm());
}
#region 处理未捕获异常的挂钩函数
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
{
Exception error = e.Exception;
if (error != null)
{
using (StreamWriter sw = new StreamWriter(_errLog, true))
{
sw.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "\t" + string.Format("出现应用程序未处理的异常 异常类型:{0} 异常消息:{1} 异常位置:{2} ", error.GetType().Name, error.Message, error.StackTrace));
}
}
else
{
using (StreamWriter sw = new StreamWriter(_errLog, true))
{
sw.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "\t" + string.Format("Application ThreadError:{0}", e));
}
}
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception error = e.ExceptionObject as Exception;
if (error != null)
{
using (StreamWriter sw = new StreamWriter(_errLog, true))
{
sw.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "\t" + string.Format("Application UnhandledException:{0}; 堆栈信息:{1}", error.Message, error.StackTrace));
}
}
else
{
using (StreamWriter sw = new StreamWriter(_errLog, true))
{
sw.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + "\t" + string.Format("Application UnhandledError:{0}", e));
}
}
}
#endregion
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。