views:

243

answers:

2

I am debugging an algorithm that is being represented by a set of ViewModels. In order to debug this algorithm I would like to redraw the View while stepping through part of the algorithm. Is this possible? (I would prefer to just repaint, not do what they call "DoEvents" to process all events.)

+1  A: 

Alas, when your debugger has stopped on a breakpoint, the debugger will suspend all threads in your application. I have a similar issue, this is what i do.

1) Instead of breakpoints, I put tracepoints with really detailed information. In visual studio, if you put curly braces , like {abc} , the value of variable ABC will be output to standard output

2) Logging. Its very useful when you cant pause your program

3) Structured exception handling. If you throw exceptions when you have problems, you can track it easier when the program begins to unwind due to error.

4) Assert as much as you can. This way if your program doesnt halt, it means everything is good in the algorithms.

Andrew Keith
It's too bad. I was debugging problems with the graphics, hence text-based output is a cumbersome approach. In principle it should be possible to refresh the screen during debugging, since I heard WPF's renderer runs on a separate thread from the main app. If one could just let the thread run during debugging it would have been nice...
Qwertie
A: 

This blog post suggests you do show a MessageBox.. I think he assumes you are using WinForms, but this could work the same way for WPF.

Omer Raviv
My window contained highly graphical information that I wanted to refresh during debugging. A message box would not be much more useful than a debugger watch or tracepoint.
Qwertie
I think you might've misunderstood the suggestion. The blog post does not suggest writing any text in the MessageBox, it suggests calling MessageBox.Show from the debugger in order to force a repaint. This is similar to calling Application.DoEvents from within the debugger as you wrote in your original message, but as the discussion in the bottom of the blog post states, it has some advantage:DoEvents just drains the queue and then returns. Blink and you'll miss it. This could be a problm if you need to rearrange your windos to make your form visible. The MessageBox will wait for a click.
Omer Raviv