Best way to kill an out of process dll ('dllhost.exe' 'COM Surrogate') when an App exits?

Viewed 4404

I am using the 'DllSurrogate' method to allow a 64-bit C# exe to talk to a 32-bit C# dll. The method is described in Hosting a .NET DLL as an Out-Of-Process COM Server (EXE).

When the App runs an extra process called 'dllhost.exe *32' automatically shows up in Task Manager, with the description 'COM Surrogate'. This is the link between the App and the 32-bit dll.

The problem I have is that this process is not killed when the App exits. Can someone suggest the recommended way of dealing with this?

I could find the process and kill it as my App closes, but I would need to make sure:

  • It is my 'COM Surrogate', not one belonging to another App.
  • It is not being used by another running instance of my App.

Is there a more direct link between my App and this process that I can check?

1 Answers
Related