c# - 如何避免 .NET CF 3.5 和 CE 6 R3 中的严重错误

标签 c# .net compact-framework windows-ce

当我在带有附加调试器的设备上启动这个示例程序时,出现了一个严重的错误。

这是我们实际应用程序中发生的情况的精简版本。

我发现的是:

  • 必须附加调试器
  • 必须以某种方式填充内存(我认为这会强制进行垃圾回收)
  • 垃圾(位图)对象必须存在。其他对象可能会导致相同的错误
  • 必须显示一个表单(使用 Application.Run() 或 ShowDialog 没有区别)

然后,当表单可见并且 GC 收集位图时,会发生严重错误。

我正在运行带有 .NET Compact Framework 3.5 的 WindowsCE 6 R3。

static class Program {

    static void Main() {
        // Fill up memory - Depends on device
        var memory = new int[100000 * 150];

        // Settings the priority higher will raise the error earlier.
        // With Priority set to Normal the EXE won't get freed correct.
        // Without this line i have to reboot the CE after every test run...
        Thread.CurrentThread.Priority = ThreadPriority.Highest;

        // 80 is just random choosen. The error occurs also with 30 Bitmaps...
        for (int o = 1; o < 80; o++) {
            // Create a Bitmap and don't free it manually. The
            // The garbage collector will take care of it :)
            var bitmap = new Bitmap(100, 100);

            // When i dispose the Bitmap, everything works fine...
            //bitmap.Dispose();
        }

        // Force a GC run
        System.Diagnostics.Debug.WriteLine(GC.GetTotalMemory(true));

        // Then error occurs when the form is shown.
        System.Windows.Forms.Application.Run(new System.Windows.Forms.Form());
    }
}

我已经找到了类似的问题,但没有答案......

到目前为止我尝试了什么:

  • 手动清理所有资源。我已经搜索了所有位图创建并处理或缓存了它们。错误仍然存​​在,不仅仅是位图有问题...

最佳答案

我有一个理论,那就是系统正在交换。如果调试器尝试检索自身大小超过 CE's paging pool 的变量的内容大小,我可以想象这会陷入僵局。调试器停止系统读取数据,但系统无法提供内容,因为它无法交换数据。使用 IOCTL_HAL_GET_POOL_PARAMETERS,您应该能够检测系统是否正在交换。

关于c# - 如何避免 .NET CF 3.5 和 CE 6 R3 中的严重错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16356606/

相关文章:

c# - XNA 键枚举中反引号 (`) 键的名称是什么?

c# - SmartDevice 应用程序的自定义消息过滤器

compact-framework - 为紧凑框架预编译 protobuf-net 类型模型

c# - 如何在 Windows Phone 7 的后台线程上运行函数?

c# - txt 文件读取/覆盖/追加。这可行吗? (视觉 C#)

c# - 必填字段验证器的 ControltoValidate 属性

c# - 通过服务帐户使用 Google SpreadsheetsService

.net - "Or"等价于 LinqWhere() lambda 表达式

c# - 一线程挂起

c# - 如何在没有 nuget.exe 或 Visual Studio 扩展的情况下下载 Nuget 包?