I have a VB6 application that references a VB6 ActiveX.exe application that references a C# .Net library through COM. That C# library has a registerable callback method which I bubble up to the original app. The C# library has two methods. One simply calls the callback. The other signals an event that triggers a simple thread to call the callback. If in my original application, I only use the direct method, when I set the activeX = Nothing, the activeX application disappears from the task manager window. If I simply call the threaded method once, on termination the activeX application will not disappear from the task manager for up to five minutes. It eventually does go away. Has anyone ever dealt with such behavior and if so, how do I get the activeX to terminate?
3 Answers
Most likely, your C# objects don't implement IDisposable and you aren't disposing of them explicitly. In that case, if you pass a callback object from your VB6 activex exe into the C# lib, it's holding that reference in it's objects even after you've released the objects because C# it garbage collected. Eventually, when the collector cleans up, it releases those C# objects, which then releases the references to your VB6 callback objects and everything clears up.

- 4,868
- 2
- 22
- 32
-
Great - good clue. It's not that IDispose was not implemented, it turns out to be the fact that the VB6 ActiveX application was using Class_Terminate to kill the C# COM reference. Class_Terminate isn't called until the callback reference is destroyed - which wasn't happening. After seeing this comment and others, I moved the destruction process into simple methods and called them from the top. I set the reference to the callback to "Nothing" and in the callback registration method, I called GC.Collect after setting the local reference to nothing. All exits fine now. Thanks folks. – Hendrik Vis Nov 08 '10 at 17:20
Someone posted a link to a book titled .NET Gotchas elsewhere that may be relevant to your issues. I've since ordered the book but it has not arrived yet. Basically, the garbage collector hasn't finished having a smoking break and collected the unused objects.

- 2,121
- 1
- 22
- 41
Likely as the other answers stated it is the garbage collector. Since you know when your VB6 application is terminate try passing nothing to the .NET callbacks and see if that forces the release early.
Make sure you are doing explicit clean up on Terminating any VB6 based component.

- 7,196
- 1
- 20
- 37