views:

509

answers:

1

I'm working on a VSTO Outlook 2007 add-in that basically synchronizes Outlook data with web service. There are three types of synchronization that I want to have in the app: startup sync, manual sync and sync on shutdown. The first two as simple and are already done.

However I have problems finding an appropriate event to fire to handle my sync on shutdown. I tried hooking to the following two events but it seems that they are fired too late when add-in doesn't have access to Outlook data and this just doesn't work:

  • ((Outlook.ApplicationEvents_Event)Application).Quit (this one fires first, but it's already too late to access Outlook data collections and update them)
  • ThisAddIn.Shutdown (this one fires after Quit so it's not good as well)

Are there any other events that are fired before those ones on Outlook shutdown that I could use? Or maybe someone knows any other way to handle sync-on-shutdown in Outlook add-in?

+2  A: 

Explorer.Close() and Inspector.Close() fire before Application.Quit() - in them you can check:

  • In Explorer.Close(): Application.Explorers.Count<=1 and Application.Inspectors.Count==0
  • In Inspector.Close(): Application.Explorers.Count==0 and Application.Inspectors.Count<=1

If so, Outlook will close and you can fire your events. Just keep in mind that Outlook can be started window-less too (automation etc.) if thats an issue for you.

Georg Fritzsche