日期:2014-05-17  浏览次数:21222 次

如何让C#程序崩溃时不弹出.net错误?

我的想法是崩溃时,仅仅友好的告诉客户:程序崩溃了。
错误信息打算写log,有人有过这样的例子吗?

------解决方案--------------------
try
{
}
catch(Exception e)
{
//记录错误信息
}
------解决方案--------------------
Main入口。
 /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main(string[] path)
        {
            Program prog = new Program();
            try
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Application.ThreadException += (System.Threading.ThreadExceptionEventHandler)delegate(object sender, System.Threading.ThreadExceptionEventArgs e)
                {
                    //这里处理线程异常
                };

                AppDomain.CurrentDomain.UnhandledException += (UnhandledExceptionEventHandler)delegate(object sender, UnhandledExceptionEventArgs e)
                {
                    //这里处理其他未捕获的异常信息
                };

               Application.Run(new MainForm);
            }
            catch (Exception ex)
            {
                //这里处理标准异常
                MessageBox.Show("程序出错:" + ex.Message);
                Application.Exit();
            }
        }

------解决方案--------------------

// Starts the application. 
[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.ControlAppDomain)]
public static void Main(string[] args)
{
    /