How to cleanly release resources used by .NET ActiveX Control when IE closes


How to cleanly release resources used by .NET ActiveX Control when IE closes



I am using a .NET ActiveX control to an interface with a USB device. The supplier of the control says the we must call the control's Shutdown() method when we are through using the device. This is problematic for a me as it is not easy to determine when the users are through using the control because it is used between pages and I can only tell when a page is unloaded, not when the user leaves the application.

Doesn't the browser notify all ActiveX controls when it closes and can't all the resources used by the control be taken care of then?




Microsoft Office Web Components IE Security Issue

1:



Ajax updater not working in internet explorer
The short answer is "no, you have no way of knowing when the browser is going away." .
Does Low Pro Prototype DOM Builder work in IE?
The long answer is as follows:.
Element.appendChild() chokes in IE
  1. In IE6 and IE7 you can have BHOs in each tab, and maintain a global, process-wide count of open tabs by atomically incrementing a count when each BHO gets constructed, and atomically decrementing the count when you get a DWebBrowserEvents2::OnQuit message.


    IE web browser control res:// usage
    Then, when the count gets to one, and you get an OnQuit message, you know you're the last tab and the process is going away.
  2. In IE8 you're out of luck because it does the process separation thing, and even then you could try to rig something up, but tab host processes don't go away when all their tabs are closed.


    Mouse coordinates in Internet Explorer
    They stick around for awhile in case a new tab opens.
But none of this really matters, since you just want to cleanup when your control is destroyed, which is when the page navigates.


c# hosting a usercontrol in IE
I'm not sure what you mean by "[the control] is used between pages", since that really isn't supported.


How to get jQuery effects working on Firefox and Google Chrome?
. The proper way to know your control is going away is to implement IOleObject and IE will call IOleObject::SetClientSite(NULL) when it is time for you to go away.

When you get the NULL site, you cleanup.

.



79 out of 100 based on 59 user ratings 409 reviews

@