使用 3G 时应用程序崩溃 [英] Application crash when using 3G

查看:27
本文介绍了使用 3G 时应用程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个应用程序,它使用套接字连接多个服务器.该应用程序在 WI-Fi 连接下运行良好,但在 3g 连接上崩溃(当然在真实设备上,在模拟器上一切正常).我无法调试它,因为它可以在手机连接到 PC 时工作.如何处理这个问题?提前致谢

I developed an application wchich is using sockets to connect with several servers. The application works fine with WI-Fi connection but crashes on 3g connection (of course on real device, on emulator everything works fine). I cannot debug it due to the fact that it works wken phone is connected to PC. How to handle this problem? Thanks in advance

推荐答案

同时订阅 Application.UnhandledException(用于 UI 线程异常)和 AppDomain.Current.UnhandledException(对于所有未处理的异常) 并尝试在进程终止之前写入文件.

Subscribe to both Application.UnhandledException (for UI thread exceptions) and AppDomain.Current.UnhandledException (for all unhandled exceptions) and try to write to a file before your process is terminated.

应用程序崩溃后,使用 ISETool 命令行将数据复制回您的机器.

After the application crashes, use the ISETool command line to copy the data back to your machine.

Application.Current.UnhandledException += (s,e) => 
    WriteExceptionFast(e.ExceptionObject, "ApplicationUnhandled");

AppDomain.Current.UnhandledException += (s,e) => 
    WriteExceptionFast(e.ExceptionObject, "AppDomainUnhandled");

private void WriteExceptionFast(Exception ex, String name)
{
    string filename = Path.ChangeExtension(name, ".log");

    using (var store = IsolatedStorageFile.GetUserStoreForApplication())
    using (var stream = store.CreateFile(filename))
    using (var writer = new StreamWriter(stream))
    {
        writer.WriteLine(ex.ToString());
        writer.Flush();
    }
}

这篇关于使用 3G 时应用程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆