When i start this sample program on the device with an attached debugger a serious error occurs.
This is a stripped down version of what happens in our real application.
What i found out is:
- Debugger must be attached
- Memory must be filled somehow (I think this will force garbage collection)
- Garbage (bitmap)objects must exist. Other Objects might lead to the same error
- A form must be shown (No difference if Application.Run() or ShowDialog is used)
Then when the form is visible and the GC collects the bitmaps a serious error occurs.
I'm running WindowsCE 6 R3 with .NET Compact Framework 3.5.
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());
}
}
I've already found similar questions but no anwser...
- How to debug a fatal error that happens after calling Application.Exit() in .NET CF 3.5 WinForms application for Windows CE 6?
- CE 6.0 / .NET CF 3.5 Application has encountered a serious error (MC3100)
What i've tried so far:
- Clean all resources manually. I've already searched all bitmap creations and disposed or cached them. The error still occurs, it's not only the Bitmaps that are bad...