2013-09-28 72 views

回答

0

您可以使用AppDomain.UnhandledException事件。代碼的主要方面來自鏈接。

AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionEventHandler(MyHandler); 

//event handler 
static void MyHandler(object sender, UnhandledExceptionEventArgs args) 
{ 
    Exception e = (Exception) args.ExceptionObject; 
    Console.WriteLine("MyHandler caught : " + e.Message); 
} 

看來CF沒有等效的ThreadException。然而,根據this post,它並不需要它:

隨着NETCF 2.0,我們還沒有Application.ThreadException但是, 不像臺式機的情況下,我們並不需要它,因爲NETCF 2.0 AppDomain.UnhandledException捕獲全部未處理的異常。

我認爲從2.0到3.5沒有什麼變化。