This sounds like a job for
System.Runtime.InteropServices.Marshal.ReleaseComObject! I'd recommend you
use a try...finally pattern to ensure the COM objects always get released.

Hope this helps!
-Andy Hopper
http://www.dotnetified.com

----- Original Message -----
From: "Pandha Permjeet, Slough" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 23, 2004 12:43 PM
Subject: [ADVANCED-DOTNET] COM Interop and freeing references


> Hi,
>
> I have a .net app that uses a legacy COM Server component built as a VB6
> ActiveX Exe.
>
> I have added a reference to it using Visual Studio 2003 References menus
and
> can use it perfectly well from my C# app.
>
> When the component is used, Windows runs it in a separate process. If
you're
> using this in a VB app then you can simply free the reference by doing a
> "Set myref = null" and the process automatically disappears.
>
> The problem is how can I achieve the same effect in .Net/C#. The component
> is designed to be activated and released many times during the lifetime of
> an application, if the reference cannot be freed then you will have many
of
> these processes running. Even if the reference to the component goes out
of
> scope or is set to null it does not release the process. I would think
that
> it would be released if the reference is garbage collected but it is not
> possible to directly invoke a collection (I've tried GC.Collect() with no
> effect).
>
> Any suggestions?
> Thanks
> Permjeet Pandha
>
>
>
>
> Scanned for viruses by MessageLabs. The integrity and security of this
message cannot be guaranteed. This email is intended for the named recipient
only, and may contain confidential information and proprietary material. Any
unauthorised use or disclosure is prohibited.
>
> ===================================
> This list is hosted by DevelopMentor�  http://www.develop.com
> Some .NET courses you may be interested in:
>
> NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
> http://www.develop.com/courses/gaspdotnetls
>
> View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to