我需要處理App.xaml.cs文件的Application_UnhandledException事件中的異常。我使用e.ExceptionObject獲取Exception對象。現在,我需要在WebClient的幫助下使用WCF服務將異常詳細信息發送到我的服務器。Windows Phone 7 - 使用WebClient處理Application_UnhandledException中的錯誤
無論何時我使用WebClient向WCF服務發送請求,它都會發送請求,但會發送回叫事件,例如webClient_UploadStringCompleted永遠不會被執行。我讀的異常都在單獨的線程處理等
我已經嘗試過,但沒有成功:
- 的ThreadStart
- 螺紋
- App.Current.RootVisual.Dispatcher.BeginInvoke
- RootFrame.Dispatcher.BeginInvoke
- System.Windows.Deployment.Current.Dispatcher.BeginInvoke
- Deploymen t.Current.Dispatcher.BeginInvoke
任何人都可以告訴,如何將錯誤信息從Application_UnhandledException發送到WCF服務與WebClient?
代碼:
//代碼得到執行,對未處理的異常
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
e.Handled = true;
// Option 1
Thread thread = new Thread(() => MainPage.HandleException(e.ExceptionObject));
thread.Start();
ThreadStart start = new ThreadStart(NonUIWork);
// Option 2
Thread thread = new Thread(start);
thread.Start(e.ExceptionObject);
// Option 3
Deployment.Current.Dispatcher.BeginInvoke(delegate { MainPage.HandleException(e.ExceptionObject); });
// Option 4
App.Current.RootVisual.Dispatcher.BeginInvoke(MainPage.HandleException, e.ExceptionObject);
// Option 5
RootFrame.Dispatcher.BeginInvoke(() => { MainPage.HandleException(e.ExceptionObject); });
// Option 6
MainPage.HandleException(e.ExceptionObject);
}
在MainPage.HandleException方法,我送例外細節WCF服務,WebClient的對象。但是,WebClient(webClient_UploadStringCompleted)的回調函數從未得到執行。看起來執行Application_UnhandledException事件的線程正在被立即掛起。
你能只是張貼一些代碼,以顯示您在異常處理程序在做什麼,發送錯誤描述。 – 2011-06-02 07:09:39
@Amresh Kumar添加了代碼片段。 – 2011-06-02 08:39:14