1

Thanks for looking.

I am developing an Outlook plugin that needs to prompt the user to log in upon loading of Outlook. I am currently accomplishing this by hooking into the Startup event of ThisAddIn.

Problem

Unfortunately, the log in dialog is displaying before Outlook is fully loaded so it appears to the user as if Outlook is not loading and they are being forced to log in for the plugin.

Question

Is there an event that can be subscribed to from within my plugin code that will only fire after Outlook has fully loaded and is being displayed to the user?

Related links

Ready event in Microsoft Outlook 2010? (The answer regarding use of StartupComplete event via IDTExtensibility2 looks promising but I am not sure how to implement it. Any advice there is appreciated as well.)

I have tried. . .

I have tried the following but this causes the dialog to launch too soon:

private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }

private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            //Fire 3rd party code to launch log-in dialog here
        }
Community
  • 1
  • 1
Matt Cashatt
  • 23,490
  • 28
  • 78
  • 111

1 Answers1

1

Check if Application.Explorers.Count > 0. If yes, proceed. Otherwise subscribe to the Explorers.NewExplorer event and run your code in that event handler when an Explorer is shown.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Thank you Dmitry, I have attempted to subscribe to the NewExplorer event, but it seems to never fire: `Globals.ThisAddIn.Application.Explorers.NewExplorer += OnNewExplorer`. Have I done this oncorrectly? Thanks in advance – Matt Cashatt Sep 21 '16 at 22:13
  • The object that fires the events must be alive - you set up an event handler on a temporary variable created by the compiler. As soon as it is released by the GC, no events will be raised. Declare Explorers as a global;/class variable and set up the event handler on that variable. – Dmitry Streblechenko Sep 21 '16 at 22:22