Question : Quitting the Outlook Application leaves the process running

I have a simple C# .Net console application that creates an instance of Outlook, performs a simple task and then quits Outlook. The Outlook instance is created and Quit in the following way:

static Outlook.Application oApp = null;
oApp = new Outlook.Application();
oApp.Quit();

ReleaseComObject(oApp);
oApp = null;

Unfortunately the process continues to run after the Quit command has been executed meaning I have to kill the process. Where am I going wrong here?

Answer : Quitting the Outlook Application leaves the process running

Check:
http://blogs.msdn.com/eric_carter/archive/2004/10/10/240568.aspx
http://stackoverflow.com/questions/158706/how-to-properly-clean-up-excel-interop-objects-in-c  (this one is for Excel but the same principles applied)

Basically you need:
1) Null all references to Outlook objects
2) the code below to Force a garbage collection:
   GC.Collect();
   GC.WaitForPendingFinalizers();
Thus your clean up code will look like:
   ReleaseComObject(oApp);
   oApp = null;
   GC.Collect();
   GC.WaitForPendingFinalizers();

Note: Please close all outlook instances before testing this code; or better restart your PC.
Random Solutions  
 
programming4us programming4us