Closing COM-Interop Application
-
I have a simple C#-(Windows-)Application. The Main-Form has two COM-Members. Working with this variables is ok, everything works as expected. When i close the application by the menu, i call Close() in the event-handler and everything is ok, but when i close by systemmenu or alt-f4 i got a com-leak. What is the reason, what is missing ?
-
I have a simple C#-(Windows-)Application. The Main-Form has two COM-Members. Working with this variables is ok, everything works as expected. When i close the application by the menu, i call Close() in the event-handler and everything is ok, but when i close by systemmenu or alt-f4 i got a com-leak. What is the reason, what is missing ?
Hi, sorry for asking you, but what is a COM-leak? How does you know it is one? (Exception, error etc.?) Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Hi, sorry for asking you, but what is a COM-leak? How does you know it is one? (Exception, error etc.?) Regards Sebastian
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
At the end of the programm, INSIDE the COM-Component it is checked wether all references are "freed", this means if the refcounts are down to zero. The component is not only one single object, instead the library contains an object-hierarchy.
-
At the end of the programm, INSIDE the COM-Component it is checked wether all references are "freed", this means if the refcounts are down to zero. The component is not only one single object, instead the library contains an object-hierarchy.
It is possible to "hook" into the event if Alt-F4 is called. Do you got a Forms-application? If yes you can register an event handler for FormClosing. Within this handler you can call the close-method for your COM.
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
It is possible to "hook" into the event if Alt-F4 is called. Do you got a Forms-application? If yes you can register an event handler for FormClosing. Within this handler you can call the close-method for your COM.
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
If have tried Form_Closed and/or Form_Closing event to call Marshal.ReleaseCOMObject(). But it doesn't help,
-
If have tried Form_Closed and/or Form_Closing event to call Marshal.ReleaseCOMObject(). But it doesn't help,
Hmmmm... Other way could be to go into the Dispose()-method of the form and to call the release-method there.
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
-
Hmmmm... Other way could be to go into the Dispose()-method of the form and to call the release-method there.
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.
Thanks for the tip. In the ...Designer.cs i modified Dispose
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); if (m\_Session != null) { while (true) { if (Marshal.ReleaseComObject(m\_Session) <= 0) { m\_Session = null; break; } } } if (m\_System != null) { while (true) { if (Marshal.ReleaseComObject(m\_System) <= 0) { m\_System = null; break; } } } } base.Dispose(disposing); }
but it doesnt't help, because the code isn't called at all, have i misunderstood you ?
-
Thanks for the tip. In the ...Designer.cs i modified Dispose
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); if (m\_Session != null) { while (true) { if (Marshal.ReleaseComObject(m\_Session) <= 0) { m\_Session = null; break; } } } if (m\_System != null) { while (true) { if (Marshal.ReleaseComObject(m\_System) <= 0) { m\_System = null; break; } } } } base.Dispose(disposing); }
but it doesnt't help, because the code isn't called at all, have i misunderstood you ?
No, you didn't misunderstood me :) Hmm... now i'm just at a loss. Normally, if you press Alt-F4 the FormClosing-event should be called. At least Dispose...
It's not a bug, it's a feature! Check out my CodeProject article Permission-by-aspect. Me in Softwareland.