0

I'm trying to quit outlook.application after I'm done with the object like the following

//variables intialisation
 var outlookApp = new Microsoft.Office.Interop.Outlook.Application();
 RDOFolder store;
 RDOStore mailbox;
 RDOSession session;

 session = Redemption.RedemptionLoader.new_RDOSession();
 session.MAPIOBJECT = outlookApp.Session.MAPIOBJECT;
 mailbox = session.GetDefaultFolder(rdoDefaultFolder.olFolderInbox).Store;
 store = session.GetDefaultFolder(rdoDefaultFolder.olFolderInbox).Parent;

//...code goes on

//Quitting
session.LogOff();
outlookApp.Quit();
Marshal.ReleaseComObject(store);
Marshal.ReleaseComObject(mailbox);
Marshal.ReleaseComObject(session);
Marshal.ReleaseComObject(outlookApp);

What could be the problem? I trying to wait for a couple minutes to make sure they were nothing going on in the outlook process bloking it to quit but it never close itself. When I click on the outlook icon to close it manually I get the following error:

Outlook cannot display this view

But If I break before session.LogOff(), open outlook in full mode and restart the code then it will close without problem.

Thanks!

Machinegon
  • 1,855
  • 1
  • 28
  • 45
  • possible duplicate of [Code behavior different outlook api fullscreen/tray](http://stackoverflow.com/questions/18382843/code-behavior-different-outlook-api-fullscreen-tray) – Machinegon Aug 24 '13 at 02:51

1 Answers1

1

You are killing the Outlook MAPI session by calling RDOSession.Logoff. Don't do that - the session belongs to Outlook, you just borrowed it by reading the Namespace.MAPIOBJECT property.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I removed that line, but the process continues anyway. – Machinegon Aug 21 '13 at 17:36
  • It's intermittent now, sometimes the process goes on and does not quit sometiems it does. Do you have more clues? Is it related to a COM object still referenced in memory? – Machinegon Aug 22 '13 at 14:15
  • So the UI is gone and only outlook.exe remain in memory? Why exactly are you trying to restart Outlook? You can just log in using RDOSession.Logon and specifying the profile that you want. – Dmitry Streblechenko Aug 23 '13 at 20:46
  • This problem is linked to this other problem : http://stackoverflow.com/questions/18382843/code-behavior-different-outlook-api-fullscreen-tray , if outlook is not in tray it does not close the process stay active. I will close it, refer to the other topic. – Machinegon Aug 24 '13 at 02:48