We are writing a contact syncing application for Outlook using .Net 3.0. We're using "Microsoft Outlook 12.0 Object Library" or Microsoft.Office.Interop.Outlook;
We notice when we call:
ApplicationClass app = new Microsoft.Office.Interop.Outlook.ApplicationClass();
It will start Outlook if the user does not have it open. But if the user closes Outlook while our application is open, we get a COMException the next time we reference the Outlook ApplicationClass instance.
How can we compensate for this behavior? We do not want to re-open Outlook if we get this exception.
We would rather Outlook not start up at all, or be hidden, but we want the user to be able to use Outlook even if our application is open.
We could also somehow hook into an ApplicationExit event or something, but if we create a new ApplicationClass at this point, would it start Outlook again?
How can we fix this?