Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Debugger interacting badly with my UI updates

$
0
0

I put together a Turtle-logo like package in WPF in support of my open source textbook that I'm using to teach C#.    It works fine, with one remaining problem that I cannot seem to sort out. 

My turtle lines are represented as a WPF PolyLine, and I programattically add points as the turtle moves about.  To allow slow animation of, e.g. drawing a maze or a spiral, I can make the thread sleep between draws, but then I have to force the GUI to update (like WinForms "DoEvents" or "Refresh").   I've found two workable solutions to this on the forums, both involving posting some work to the Dispatcher: the one posts a low-priority empty delegate into the work queue, forcing the higher priority renderer to go first.  The other creates a new Dispatcher Frame for a fresh message pump - and it runs and does the GUI updates that I need.   So both work fine when I'm not single stepping in the debugger. 

But, if I set a breakpoint and add a point to my PolyLine, (and try to flush the updates to the GUI), the debugger interaction pre-empts the GUI update.   But when I execute the next single-step to add the next point to the polyLine, the previous line segment appears on the GUI.  So single-step debugging (which I want for educational purposes) updates my GUI sometimes one step behind where I'd like it :-(

There seems to be a race condition between the debugger grabbing control, or allowing the GUI update to complete first.  So behaviour is sometimes inconsistent: I extend the polyline and see it immediatedly before debugger regains control, other times I extend the polyline and it doesn't appear before the debugger regains control.

I've stripped everything down to a single WPF program that is about 120 lines of C# to illustrate the core of my problem.   Since I can't see how to make an attachment here, (and the post on't accept a link), you can get the zipped project at 
http://www.ict.ru.ac.za/Resources/cspw/RefreshSpike.zip 

When I developed the code I had no problems.  But our lab machines are windows-64 bit, I run 32-bit on my dev machine. (All at Framework 4.0)   If anyone knows of any deep changes in the way the debugger and the Dispatcher interact, it may give a clue.   I use Visual Studio 2010, for the record, but under VS 2012 on the 64-bit system the problem remains.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>