Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / October 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robin - 19 Oct 2005 15:28 GMT
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();
     }
  }
}
Phil Wilson - 19 Oct 2005 16:38 GMT
Marshal.ReleaseComObject might help.
Signature

Phil Wilson
[Microsoft MVP-Windows Installer]

> 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
[quoted text clipped - 31 lines]
>   }
> }
Robin - 19 Oct 2005 16:51 GMT
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.

> Marshal.ReleaseComObject might help.
Robin - 19 Oct 2005 17:02 GMT
Apologies - it wasn't an interop problem at all. I needed to call Quit on
Word. Then the process terminates. :-(

> 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.
>
> > Marshal.ReleaseComObject might help.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.