调试事件处理程序和断点 [英] debugging event handler and breakpoints

查看:94
本文介绍了调试事件处理程序和断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio Tools for Applications 2008创建Revit Architecture的宏.有谁知道是否有用于调试事件处理程序的技巧或设置?每当我尝试在事件处理程序中设置断点时,VSTA都会跳过它们.在其他任何地方,它们都可以正常工作.

事件处理程序中的代码正在执行.因此将调用处理程序.

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.

推荐答案

Paul,

在事件处理程序中设置调试断点绝对没有什么特别的.如果您的其他断点正常工作,而即使在处理程序中也无法正常工作,则可以确定:不会调用处理程序.

我想您也没有这个问题,很有可能您设置事件处理程序时只有一个问题:即将代理实例添加到事件的调用列表中.我怀疑是基于我在CodeProject的许多其他问题中看到的问题.

除了断点,您还可以执行以下操作:对于每个事件,都难以找到各自的运算符"+=",因为使用它是更新事件调用列表的唯一方法. (如果您没有其中的一些,则适当添加:-))在您有"+="的每一行上放置一个断点,并检查代码是否到达那里.如果您发现电话丢失,则可以解决您的问题.

许多事件不会发生,因为开发人员在解雇时做出了错误的假设.例如,默认情况下,Form上具有任何可聚焦控件的键盘事件都不会发生.您需要设置Form.KeyPreview = true.有很多这样的情况.

如果仍有问题,则需要编写代码示例. (警告!请不要发布答案,请使用改善问题"或添加评论".)

—SA
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


最终的解决方案是重新启动计算机,然后重试.
The final solution was to reboot the computer and try again.


这篇关于调试事件处理程序和断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆