Dispose C # DLL tagged for COM interoperability

I created a C # vanilla dll and tagged it for COM inter op. A DLL is a simple user form without any functionality, as it is an experiment.

I registered the DLL and opened the active test container x and instantiated my COM object. It appears in the test container, and I can view the public methods of the control - these are the default methods, not the ones I created.

i then exit the active test container x, and I noticed that the test container is still hiding in the task manager and that I had to kill the process manually. This makes me think that the test container still contains a link to my C # dll exposed for com inter op.

The default dispose method in designer.cs

 protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);


   }

Quick Time, , , , , .

- -, dispose? , , , #, , , - .

+3
3

:

public void IDisposable.Dispose()
{     
   System.Runtime.InteropServices.Marshal.ReleaseComObject(this);
}

COM- .net, . . , : -)

:

:

GC.SuppressFinalize();

+3
+1

In addition to overriding Dispose (bool), you need to override IDisposable.Dispose () in this method, which you call Dispose (true), then call GC.SurpressFinalize (this). You should also call Dispose () on all members that implement IDisposable in a Dispose (bool) override

0
source

Source: https://habr.com/ru/post/1702134/


All Articles