views:

480

answers:

1

In my Silverlight project I have a thread that fires every x milliseconds. In this thread I was attempting to change the state of the application. This wasn't working and I didn't know why, so put a breakpoint in to the Timer callback. The breakpoint was hit, but the minute I attempted to change the state it just bailed out of the function (assuming an exception has been thrown).

I know why the error occurred - you can't change GUI stuff via a non-GUI thread.

My question is - how can I get Visual Studio to actually break when an exception like that occurs? (Rather than just silently bailing out, which doesn't notify me if there is a problem).

I've tried the "Break when exceptions cross AppDomain or managed / native boundaries", but that didn't have any effect.

+2  A: 

Can you change the break handling for InvalidOperationException so it breaks immediately rather than only if it's unhandled?

Jon Skeet
How can you do that?
Mark Ingram
Debug Menu -> Exceptions -> CLR Exceptions -> System -> System.InvalidOperationException: tick the checkbox in the "Thrown" column. You may get some false positives, but it should (I believe) catch the case you're interested in.
Jon Skeet
Thanks John - I knew there was a place to do that. It caught my exception - but not where I was expecting it! The problem was the UnhandledException event was firing, then attempting to display an alert box, which you can't do in non-GUI thread.
Mark Ingram