views:

216

answers:

6

How do I put a breakpoint at every MessageBox in my application?

A: 

Press ctrl-F to bring up the search dialog. Search for MessageBox.Show Right-click on the line of code and select Breakpoint -> Insert Breakpoint

Calanus
Doing this over more than say... 3 messageboxes would be insane...
MunkiPhD
+4  A: 

Write a wrapper function around MessageBox, replace all your calls to MessageBox with that wrapper function, put a breakpoint inside your wrapper function.

Adrian Grigore
A: 

This may not be possible but if you find and replace your MessageBox call and add a call (before the call to the MessageBox) to a function that has a breakpoint inserted then you can step on from there.

Nicholas Murray
A: 

You could do a find and replace:

replace

.ShowDialog();

with

.ShowDialog();
#ifdef dialogDebugging
System.Diagnostics.Debugger.Break();
#endif

Then define dialogDebugging in your project settings.

Ian
+9  A: 
Kirill V. Lyadvinsky
Have to set the language as "Unknown" or the IDE won't find the function.
Nifle
I've updated image. I think that to make it working in C# the function name should be fully qualified.
Kirill V. Lyadvinsky
+2  A: 

Select Debug > New Breakpoint > Break at function. This gives you a pop-up. Enter the fully qualified name of the method you want to break at. If it is a framework method, VS will tell you that the name can't be verified but you're still allowed to set it. E.g. to break on all System.Console.WriteLine enter that and accept the warning.

Now, when you run the application VS will stop in WriteLine, but since you probably do not have source files for that, VS will not jump to the right place. However, the call stack will be correct, and you can navigate backwards from there.

Brian Rasmussen