如何知道带有 ActiveX(COM) 控件的 IE 选项卡(窗口)已关闭?
我在 Internet Explorer 中使用的 C# 中实现了 ActiveX ( COM ) 控件。我的控件使用非托管资源,我需要知道何时关闭带有控件的选项卡(窗口)以释放资源。
我的控件如何知道带有 ActiveX( COM ) 控件的 IE 选项卡(窗口)已关闭(窗口关闭时没有 javascript 调用控件方法)?
I have ActiveX ( COM ) control implented in C# that used in Internet Explorer. My control uses unmanaged resourses and I need know when tab(window) with control will be closed to release resources.
How my control can know that IE tab (window) with ActiveX( COM ) control was closed (without javascript call control methods when window closed)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您正在编写
UserControl
覆盖OnHandleDestroyed
并将资源释放代码放在那里。不要忘记在该方法中的代码之后调用
base.OnHandleDestroyed
。If you are writing a
UserControl
overrideOnHandleDestroyed
and place your resource releasing code there.Don't forget to call
base.OnHandleDestroyed
after your code in that method.ActiveX 控件基于 COM,它使用引用计数。当引用计数变为零时,您的控件应该处置其资源。从 C# activex 控件中检测到这一点并不简单,但根据 这个问题的答案,是可行的。
An ActiveX control is based on COM, which uses refcounting. Your control should dispose its resources when it's refcount goes to zero. This is not trivial to detect from a C# activex control, but according to this question's answer, it is doable.