Outlook VSTO - How to identify when Outlook is fully loaded

Viewed 193

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

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.

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

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

Darrin

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");
}

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 ...

2 Answers

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.

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

  private Outlook.Reminders m_Reminders;

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");
   }

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

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.

There is no such thing as "fully loaded and updated all stores" - the stores are continuously being updated.

Why exactly do you need to enable your buttons only when something like that happens? Do you get an error if you code is invoked? In that case, you really need to take a look at those errors and figure out why they are raised.

Related