all groups > dotnet interop > october 2005 >
You're in the

dotnet interop

group:

Unmanaged COM process doesn't exit when .NET client ends


Unmanaged COM process doesn't exit when .NET client ends Robin
10/19/2005 7:28:07 AM
dotnet interop:
I'm sure it's something simple I'm overlooking but... I have a .NET app
written in C#. I imported a couple of different COM servers via the Add
Reference->COM window. I then start up the servers by "new"ing them up (see
example code below). The server starts up correctly. The problem is that when
my application exits, the server doesn't go away. I.e. if I look at Task
Manager, I still see the process running - in the case of my example,
Winword. I thought maybe it just took a couple of minutes for the process to
be released but no matter how long I wait, it doesn't go away and I have to
manually kill the process. Any ideas what I'm doing wrong?

Thanks, Robin

EXAMPLE CODE:

using System;
using System.Runtime.InteropServices;
using System.Reflection
using Word = Microsoft.Office.Interop.Word;

namespace MySpace
{
class Driver
{
private Word._Application m_word;

internal void startWord()
{
m_word = new Word.Application();
}
}
}
Re: Unmanaged COM process doesn't exit when .NET client ends Phil Wilson
10/19/2005 8:41:14 AM
Marshal.ReleaseComObject might help.
--
Phil Wilson
[Microsoft MVP-Windows Installer]

[quoted text, click to view]

Re: Unmanaged COM process doesn't exit when .NET client ends Robin
10/19/2005 8:51:03 AM
Thanks but no, it didn't. Since posting, I tried making my C# class derive
from IDisposable and added the ReleaseComObject call to the Dispose method. I
then call Dispose explicitly on my Driver class. No luck... the server
process still hangs around.

[quoted text, click to view]
Re: Unmanaged COM process doesn't exit when .NET client ends Robin
10/19/2005 9:02:01 AM
Apologies - it wasn't an interop problem at all. I needed to call Quit on
Word. Then the process terminates. :-(

[quoted text, click to view]
AddThis Social Bookmark Button