main.cs

来自「CS导航Logo ,在Logo上显示Loading」· CS 代码 · 共 69 行

CS
69
字号
using System;
using System.Configuration;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using System.Windows.Forms;

namespace BufferedUploadWin
{

	/// <summary>
	/// Summary description for Main.
	/// </summary>
	class AppStart
	{
		[STAThread]
		public static void Main() 
		{
			try 
			{
				SubMain();
			} 
			catch (Exception e) 
			{
				HandleUnhandledException(e);
			}			
		}

		public static void SubMain() 
		{
			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);		// CLR
			Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(OnGuiUnhandedException);	// Windows Forms
			Application.EnableVisualStyles();
			Application.Run(new Form1());
		}

		// CLR unhandled exception
		public static void OnUnhandledException(Object sender, UnhandledExceptionEventArgs e) 
		{
			HandleUnhandledException(e.ExceptionObject);
		}

		// Windows Forms unhandled exception
		public static void OnGuiUnhandedException(Object sender, ThreadExceptionEventArgs e) 
		{
			HandleUnhandledException(e.Exception);
		}

		public static void HandleUnhandledException(Object o) 
		{
			if(o == null)
			{
				MessageBox.Show("An unknown error has occurred in this app. ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
				return;
			}
					
			Exception ex = o as Exception;
			if (ex != null) 
			{ 
				if(ex.GetType().Name == "ThreadAbortException") 
					return;	// ignore.  these are in response to the user cancelling a thread, so don't report any errors.				
				else
				{
					MessageBox.Show(ex.ToString());
				}
			}
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?