Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm using Visual Studio Tools for Applications 2008 to create macros for Revit Architecture. Does anyone know if there is a trick or setting for debugging event handlers? Whenever I try setting breakpoints in the event handlers VSTA just skips over them. Anywhere else and they work fine.

The code in the event handler is being executed. So the handler is being called.
Posted
Updated 5-Feb-11 7:35am
v2

Paul,

There is absolutely nothing special about setting debugging break points in event handler. If your other break points work and those in even handlers do not, you can be quite sure: that handlers are not called.

I guess you also have no this problem, much more likely you only have a problem setting up event handlers: that is, adding delegate instances to event's invocation list. I suspect it based on the problems I could see in many other Questions here at CodeProject.

Here is what you can do in addition to your break points: for each event you have problem with locate respective operator "+=" because using it is the only way to update the event's invocation list. (If you did not some of them, add appropriately :-) ) Put a break point on each line where you have "+=" and check up if your code ever gets there. If you find that the call is missing, you've narrowed you problem.

Many events will not happen because the developer make wrong assumptions on their firing. For example, by default keyboard events on the Form with any focusable control will not happen; you need to set Form.KeyPreview = true. There are many cases like that.

If you still have a problem, you code sample is needed. (Warning! please don't post an Answer, use "Improve question" or "Add comment".)

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 5-Feb-11 13:22pm    
Good reply
Paul Hildebrandt 5-Feb-11 13:26pm    
I know the event is firing and being called properly. I added a Messagebox.Show() call to double check that. The code in the event handler is being executed but the breakpoints in the handler are ignored for some reason but not elsewhere.
Sergey Alexandrovich Kryukov 5-Feb-11 15:07pm    
If it looks so mystical as you describe, could you show a minimal code sample to reproduce the effect under debugger? Also, do any other break points work (important)? Please answer.
--SA
Paul Hildebrandt 5-Feb-11 21:18pm    
Hehe, now I go back and try it again and the debugging works fine. I guess the next time something mystical happens I reboot the computer and put away the voodoo doll.
Sergey Alexandrovich Kryukov 6-Feb-11 0:48am    
I can tell you, there are delicate moments in debugging a mixed-mode applications (unmanaged + managed, C++ with C++/CLI), native libraries while called by .NET assemblies, etc. After some RTFM and adjustments in project and debugger options I debugged them all. As to all-managed, I never saw any problem. You should understand that event handlers are regular method called in a regular way, only the calling code is hidden in .NET, but most other cases are like that.
--SA
The final solution was to reboot the computer and try again.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 6-Feb-11 0:48am    
Did it work?
--SA
Paul Hildebrandt 6-Feb-11 18:37pm    
Yup, after I rebooted everything the breakpoints in the event handlers now stop the code. My guess is the VSTA which works behind Revit Architecture might not be as stable as it could be yet. Very frustrating but hopefully this post will spare others that frustration.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900