Kill Process

M

Max

I use late binding to have my program compatible with multiple versions of Microsoft Outlook.
Here is a snipped of my code that launches Microsoft Outlook and displays it to the user:

Code:
Type objClassType = Type.GetTypeFromProgID("Outlook.Application", true);
object objApp_Late = Activator.CreateInstance(objClassType);

// .... code here that does something .... //

object[] parameters = new object[1];
parameters[0] = objApp_Late;
objMailItem_Late.GetType().InvokeMember("Display", BindingFlags.InvokeMethod, null, objMailItem_Late, parameters);

At the very end I display the instance to the user so s/he can interact with Outlook, while my program continues on. I noticed that
when the user closes Outlook and continues using my program, OUTLOOK.EXE still lives on when you look in the task manager list,
wasting memory space. When my app opens up Outlook again and the user closes it another OUTLOOK.EXE instance remains in memory and
so on.

How can I stop this from happening? Is it possible to wait for user to quit Outlook and return to my program and clean up, or is
there a way to just kill OUTLOOK.EXE once it's closed by the user. Any idea why OUTLOOK.EXE hangs on even after it is closed by the
user?

Cheers,
Max
 
N

Nicholas Paldino [.NET/C# MVP]

Max,

Outlook hangs around because you still have references that are attached
to it. Even if you think that you have properly freed all of the
references, objects in outlook (or any office product for that matter) have
circular references, which makes them notoriously hard to release in this
environment.

The easiest way to get rid of everything is to make sure that all
references to all outlook objects are set to null and then perform a garbage
collection. This will release all of the references that you have, and
should still keep the app running, such that when you close it (equivalent
to calling Quit on the application object) it will terminate correctly.

Hope this helps.
 
M

Max

Thanks for the link. It seems to be working for Excel like the example but not for Outlook.
I wonder why Outlook has to be such a memory parasite....



Mel Weaver said:
Try this
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q317109

Mel

Max said:
I use late binding to have my program compatible with multiple versions of
Microsoft Outlook.
Here is a snipped of my code that launches Microsoft Outlook and displays
it to the user:

Code:
Type objClassType = Type.GetTypeFromProgID("Outlook.Application", true);
object objApp_Late = Activator.CreateInstance(objClassType);

// .... code here that does something .... //

object[] parameters = new object[1];
parameters[0] = objApp_Late;
objMailItem_Late.GetType().InvokeMember("Display",
BindingFlags.InvokeMethod, null, objMailItem_Late, parameters);

At the very end I display the instance to the user so s/he can interact
with Outlook, while my program continues on. I noticed that when the user
closes Outlook and continues using my program, OUTLOOK.EXE still lives on
when you look in the task manager list, wasting memory space. When my app
opens up Outlook again and the user closes it another OUTLOOK.EXE instance
remains in memory and so on.

How can I stop this from happening? Is it possible to wait for user to
quit Outlook and return to my program and clean up, or is there a way to
just kill OUTLOOK.EXE once it's closed by the user. Any idea why
OUTLOOK.EXE hangs on even after it is closed by the user?

Cheers,
Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top