Excel.Application.SelectionChange 仅触发一次
我只收到第一个事件通知,之后什么也没有发生。 有什么想法吗?
UPD:我发现了一件奇怪的事情。我的事件处理程序代码如下所示:
var cell = range.Cells[1, 1];
var rangeName = cell.Address[false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing];
我已经以这种方式更改了它,添加了显式类型转换:
var cell = (Range)range.Cells[1, 1];
var rangeName = cell.Address[false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing];
现在我的事件处理程序被调用了几次,然后才停止被调用。
I'm getting only the first event notification, and nothing happens after.
Any ideas?
UPD: I've found a strange thing. My code for event handler looked like this:
var cell = range.Cells[1, 1];
var rangeName = cell.Address[false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing];
I've changed it in this way, adding explicit type cast:
var cell = (Range)range.Cells[1, 1];
var rangeName = cell.Address[false, false, XlReferenceStyle.xlA1, Type.Missing, Type.Missing];
And now my event handler gets called several times, and only then stops getting called.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于使用 COM Interop 跟踪事件处理程序的方式,垃圾收集器可以清理 RCW,从而阻止您接收事件。
确保保留对具有事件处理程序的对象的引用,例如,而不是编写:
write
Because of the way event handlers are tracked with COM Interop, the garbage collector can clean up the RCW's which stops you from receiving events.
Make sure you keep a reference to the object that has the event handler, for instance instead of writing:
write