久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

.NET - 實現“捕獲所有異常處理程序"的最佳方

.NET - What#39;s the best way to implement a quot;catch all exceptions handlerquot;(.NET - 實現“捕獲所有異常處理程序的最佳方式是什么?)
本文介紹了.NET - 實現“捕獲所有異常處理程序"的最佳方式是什么?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想知道最好的方法是如果所有其他方法都失敗了".

I'm wondering what the best way is to have a "if all else fails catch it".

我的意思是,您在應用程序中處理盡可能多的異常,但仍然肯定會有錯誤,所以我需要有一些東西捕獲所有未處理的異常,以便我可以收集信息并存儲將它們保存在數據庫中或將它們提交到 Web 服務.

I mean, you're handling as much exceptions as possible in your application, but still there are bound to be bugs, so I need to have something that catches all unhandled exceptions so I can collect information and store them in a database or submit them to a web service.

AppDomain.CurrentDomain.UnhandledException 事件是否捕獲所有內容?即使應用程序是多線程的?

Does the AppDomain.CurrentDomain.UnhandledException event capture everything? Even if the application is multithreaded?

旁注:Windows Vista 公開了允許任何應用程序的本機 API 函數在崩潰后恢復自己……現在想不出名字……但我寧愿不使用它,因為我們的許多用戶仍在使用 Windows XP.

Side note: Windows Vista exposes native API functions that allow any application to recover itself after a crash... can't think of the name now... but I'd rather not use it, as many of our users are still using Windows XP.

推薦答案

我剛剛玩過 AppDomain 的 UnhandledException 行為,(這是注冊未處理異常的最后階段)

I have just played with AppDomain's UnhandledException behavior, (this is the last stage the unhandled exception is registered at)

是的,在處理完事件處理程序后,您的應用程序將被終止,并顯示令人討厭的...程序停止工作對話框".

Yes, after processing the event handlers your application will be terminated and the nasty "... program stopped working dialog" shown.

:)您仍然可以避免這種情況.

:) You still can avoid that.

退房:

class Program
{
    void Run()
    {
        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

        Console.WriteLine("Press enter to exit.");

        do
        {
            (new Thread(delegate()
            {
                throw new ArgumentException("ha-ha");
            })).Start();

        } while (Console.ReadLine().Trim().ToLowerInvariant() == "x");


        Console.WriteLine("last good-bye");
    }

    int r = 0;

    void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        Interlocked.Increment(ref r);
        Console.WriteLine("handled. {0}", r);
        Console.WriteLine("Terminating " + e.IsTerminating.ToString());

        Thread.CurrentThread.IsBackground = true;
        Thread.CurrentThread.Name = "Dead thread";            

        while (true)
            Thread.Sleep(TimeSpan.FromHours(1));
        //Process.GetCurrentProcess().Kill();
    }

    static void Main(string[] args)
    {
        Console.WriteLine("...");
        (new Program()).Run();
    }
}

P.S.請在更高級別處理未處理的 Application.ThreadException (WinForms) 或 DispatcherUnhandledException (WPF).

P.S. Do handle the unhandled for Application.ThreadException (WinForms) or DispatcherUnhandledException (WPF) at the higher level.

這篇關于.NET - 實現“捕獲所有異常處理程序"的最佳方式是什么?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a way to know if someone has bookmarked your website?(有沒有辦法知道是否有人為您的網站添加了書簽?)
Use of Different .Net Languages?(使用不同的 .Net 語言?)
Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Determining an #39;active#39; user count of an ASP.NET site(確定 ASP.NET 站點的“活動用戶數)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Best way to keep track of current online users(跟蹤當前在線用戶的最佳方式)
主站蜘蛛池模板: 狠狠热视频 | 国产视频第一页 | 成人小视频在线观看 | 精品国产乱码久久久久久图片 | 免费在线观看成人 | 色婷婷一区二区三区四区 | 国产中文字幕在线观看 | 日韩淫片免费看 | 欧美在线视频一区二区 | 精品亚洲一区二区三区 | 蜜桃视频在线观看免费视频网站www | 视频一区欧美 | 国产欧美精品 | 99re在线视频 | 午夜欧美一区二区三区在线播放 | 国产精品久久二区 | 秋霞a级毛片在线看 | 人人澡人人射 | 成人在线免费观看视频 | 国产清纯白嫩初高生在线播放视频 | 亚洲欧美国产精品久久 | 操久久| 亚洲一区二区三区在线 | 精品国产乱码一区二区三 | 日韩精品一区二区三区在线 | 黄色片网站在线观看 | 欧美国产日韩一区二区三区 | 国产一区二区三区日韩 | 在线观看中文字幕亚洲 | 色精品视频 | 日韩高清中文字幕 | 亚洲一区二区视频 | 一区二区三区四区五区在线视频 | 国产高清在线精品 | 老司机免费视频 | 精品久久久久久亚洲精品 | 国产免费一区二区 | 欧美一区二区三区 | 久久精品视频网站 | 国产成人久久av免费高清密臂 | 天天操天天干天天曰 |