VSTO Outlook integration - Outlook shutdown event for synchronization

爷,独闯天下 提交于 2019-12-02 04:04:43

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/1438086/vsto-outlook-integration-outlook-shutdown-event-for-synchronization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!