gpt4 book ai didi

c# - Windows Phone 7 - 使用 WebClient 处理 Application_UnhandledException 中的错误

转载 作者:行者123 更新时间:2023-11-30 22:38:10 24 4
gpt4 key购买 nike

我需要处理 App.xaml.cs 文件的 Application_UnhandledException 事件中的异常。我正在使用 e.ExceptionObject 获取异常对象。现在,我需要在 WebClient 的帮助下使用 WCF 服务将异常详细信息发送到我的服务器。

每当我使用 WebClient 向 WCF 服务发送请求时,它都会发送请求,但会发送回调事件,例如webClient_UploadStringCompleted 永远不会被执行。我读到异常是在单独的线程等中处理的。

我已经尝试过,但没有成功:

  1. 线程启动
  2. 话题
  3. App.Current.RootVisual.Dispatcher.BeginInvoke
  4. RootFrame.Dispatcher.BeginInvoke
  5. System.Windows.Deployment.Current.Dispatcher.BeginInvoke
  6. Deployment.Current.Dispatcher.BeginInvoke

谁能告诉我,如何使用 WebClient 将错误详细信息从 Application_UnhandledException 发送到 WCF 服务?

代码:

// Code to execute on Unhandled Exceptions

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 方法中,我使用 WebClient 对象向 WCF 服务发送异常详细信息。但是,WebClient 的回调函数 (webClient_UploadStringCompleted) 永远不会执行。似乎执行 Application_UnhandledException 事件的线程正在立即挂起。

最佳答案

您可以在 Windows Phone 中使用 IsolatedStorage 存储异常,当应用程序重新启动时您可以使用异步调用发送错误描述

关于c# - Windows Phone 7 - 使用 WebClient 处理 Application_UnhandledException 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6210952/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com