My C# ActiveX Control is hostet in IE 8. I want to execute code when the control is unloaded.
I tried the following:
...
public class ActiveXControl : Control
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
// Cleanup
}
}
}
...
But disposing is allways false (Called from finalizer). As I need to access managed objects I cannot use that one.
How can I get the cleanup code to be called when the Browser "unloads" the control?
I found the IOle开发者_如何学CObject::Close method, which is implemented by the Control class but AFAIK ther's no way of overriding its behavior.
I haven't done this, but as a suggestion to try: It might be possible to write a bit of javascript embedded in the html of on the web page that will call a method on your activeX control when the page is navigated away from. You could call your cleanup code from this method.
You could override OnHandleDestroyed(), called when IE destroys the control window.
精彩评论