Outlook VSTO - 如何识别 Outlook 何时完全加载 [英] Outlook VSTO - How to identify when Outlook is fully loaded

查看:108
本文介绍了Outlook VSTO - 如何识别 Outlook 何时完全加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用 C# 编写的 Outlook VSTO.我使用的是 Outlook 2016 (Office 365).

I have a Outlook VSTO written in C#. I am using Outlook 2016 (Office 365).

我正在尝试确定 Outlook 完全加载并更新所有存储的时间,如果可能的话,在发生这种情况时触发一个事件,以便我可以启用/禁用功能区中的某些按钮.

I am attempting to ascertain the moment when Outlook has fully loaded and updated all stores and if possible fire an event when that occurs, so I can enable / disable certain buttons in the ribbon.

我的问题是我如何知道 Outlook 何时完全实例化并在初始启动时完成加载所有商店?

My question here is how do I know when Outlook has fully instantiated and finished loading all stores on the initial startup?

我能够确定的最接近的是最后一个 Application.Reminder 事件何时被触发,但必须有更简单的方法.每次将提醒加载到提醒窗口时都会触发 Application.Reminder 事件,只有在所有商店都更新后,才会在 Outlook 的初始启动时显示,然后我希望触发自定义事件.

The closest I have been able to ascertain is when the last Application.Reminder event is fired, but there must be a simpler way. The Application.Reminder event is fired each time a reminder is loaded into the reminder window, which is only shown on the initial start up of Outlook once all of the stores are updated, and it is about then I wish to fire a custom event.

问了一个类似的问题 这里 没有真正的答案.

A similar question is asked here with no real answer.

MTIA

达林

我已经确定可以使用 Application.Reminders.BeforeReminderShow 事件捕获我要查找的事件 - 此事件在显示提醒窗口之前触发.

Edit 1: I have ascertained that the event I am looking for can be captured using the Application.Reminders.BeforeReminderShow event - this event fires just prior to the Reminder Window being shown.

可以在应用程序启动事件中挂接该事件..

The event can be hooked up in the Application Startup event ..

Application.Reminders.BeforeReminderShow += Reminders_BeforeReminderShow;

private void Reminders_BeforeReminderShow(ref bool Cancel)
{
    Debug.WriteLine("Reminders_BeforeReminderShow");
    MessageBox.Show("Reminders_BeforeReminderShow");
}

但是,如果另一个 VSTO 钩住了该事件,这似乎也不会触发该事件,这可能会造成竞争条件......如果另一个 VSTO 被卸载 - 事件正常触发......

However, it also seems that this event does not fire if another VSTO has hooked the event perhaps creating a race condition ... if the other VSTO is unloaded - the event fires normally ...

推荐答案

一旦我弄清楚了我需要创建一个提醒变量而不是直接使用 Application.Reminders 事件,我的问题的答案就相对容易了对象,并使用来自对象的事件.当另一个 VSTO 也访问 Reminders 集合的事件时,这种对事件的访问形式防止了我描述的竞争条件.

The answer to my question was relatively easy once I had worked out that rather than use the Application.Reminders events directly, I needed to create a variable of the reminders object, and use the events from the object. This form of access to the events prevented the race condition as I described it when another VSTO also access the events of the Reminders collection.

所以我的问题的解决方案是向 ThisAddin.cs 添加一个私有 Reminders 对象:

So the solution to my problem was to add a private Reminders object to ThisAddin.cs:

  private Outlook.Reminders m_Reminders;

然后在 ThisAddIn_Startup 实例化事件监听器:

then in ThisAddIn_Startup instantiate the event listeners:

   m_Reminders = Application.Reminders;
   m_Reminders.BeforeReminderShow += Reminders_BeforeReminderShow;

监听器的事件代码如下:

the event code for the listener is as follows:

   private void Reminders_BeforeReminderShow(ref bool Cancel)
   {
        Debug.WriteLine("Reminders_BeforeReminderShow");
        MessageBox.Show("Reminders_BeforeReminderShow");
   }

BeforeReminderShow 事件是在应用程序实例化并且商店的初始更新完成后触发的最后一个事件.

The BeforeReminderShow event is the last event fired after the application has been instantiated and the initial update of the stores is complete.

虽然我的示例没有显示它,但我有一个小方法,它被调用并更新 VSTO 功能区中的功能区按钮.

Whilst my example does not show it, I have a small method which is called and updates the Ribbon Buttons in the VSTO's ribbon.

这篇关于Outlook VSTO - 如何识别 Outlook 何时完全加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆