Reputation: 523
I'm working on a rather complex, multithreaded app that is not owned by any one person. Out of many MessageBoxes that are correct, there's at least one that needs a different message. I can get to it easily through the UI, but I have no idea where it is in the code. If I pause the debugger at that point, it goes to the Application.Run(...) method call and the Call Stack is empty.
How can I tell where that MessageBox is?
Can I have it break as soon as I close the MessageBox and take me to the code that did it?
Or perhaps pause all threads and let me see which one is close to a MessageBox.Show(...) that looks about right?
I'm using VS2008.
This code has a LOT of MessageBoxes with varying patterns. Some use MessageBox.Show(...) while others use owner.Invoke(new MessageBoxShowDelegate(MessageBox.Show),...). A very few include the message directly; most either passthrough an exception message or get their strings from a database.
I'm just another one in a long string of people that have modified this code without much internal documentation, so there's no overall structure that I can see.
Upvotes: 2
Views: 276
Reputation: 6150
Run your program in the Visual Studio debugger.
When the message box appears, pause the debugger.
Check all your threads, and the thread showing the MessageBox should be halted somewhere in the callstack at the line where the message box is called.
This is true for both WPF and WinForms as far as I can tell. If you aren't seeing anything in your call stack, you are either on the wrong thread, or have other problems like the message box caller being in a library you can't debug.
Upvotes: 5