Okay, this is a real head-scratcher:
If I select a menuitem that causes the image, that makes up the entire window (a writeableBitmap) to have some pixels drawn on it, it does so and displays correctly.
However, if I add a while loop (let's say for 5 loops) to the same method the drawing on the bitmap DOES NOT DISPLAY until the loop is completed and then the 5th redrawn bitmap is correctly displayed.
So, is there some sort of 'automatic refresh' that is happening to the window when a menuitem is selected but is being skipped in the while loop?
More details.
This works fine (brings in a 'clean' image, draws some stuff on it, displays it):
// This brings in a 'clean' image
writeableBitmap = new WriteableBitmap(CleanVegMap);
image.Source = writeableBitmap;
// This makes a bunch of draws on the bitmap
DrawDinos2d();
This, however, 'goes away' for 10 seconds and then only displays the last (i.e. 5th) image:
int z = 0;
while (z < 5){
z++;
// This brings in a 'clean' image
writeableBitmap = new WriteableBitmap(CleanVegMap);
image.Source = writeableBitmap;
// This makes a bunch of draws on the bitmap
DrawDinos2d();
}
New idea: is it possible that somehow the 5 'drawn' writeableBitmaps are being cached in memory, somehow by the system?
Tried using the Dispatcher (like below):
Dispatcher.Invoke((Action)delegate
{
writeableBitmap = new WriteableBitmap(CleanVegMap);
image.Source = writeableBitmap;
DrawDinos2d();
});
Same thing (goes away for 10 seconds and then displays only the last image.
Another clue: I just put a MessageBox in the loop at the bottom of each loop and, as I somehow suspected, it 'blitted' the redrawn screen correctly. Somehow:
System.Windows.MessageBox.Show("Glarp!");
this call 'woke up' the system. Again, any ideas?
See Question&Answers more detail:
os