none
C# Outlook Add-in Multiple Instances

    Question

  • Hi,

    I'm working on an Add-in that can run from multiple Outlook instances. I want to automatically update the displayed data from the active instance of my Add-in whenever the user switches from one Outlook window to another. Is there an event handler for this?

    Please help.

    Thanks,

    Benj




    Monday, October 07, 2013 2:51 AM

Answers

  • There is the Active method and there is the Activate event. They are completely different. When accessing the event, you need to cast the Explorer object as the particular event interface (ExplorerEvents or ExplorerEvents_10)

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Benjamin Penn Monday, October 07, 2013 7:08 AM
    Monday, October 07, 2013 6:32 AM

All replies

  • Do you mean switching between Outlook explorer windows showing the contents of different Outlook folders?

    Outlook is a singleton, there is always only one instance of outlook.3xe running for each local Windows user. If you want to check when a particular Explorer is activated, use Explorer.Activate event. If you want to know when a new Explorer is opened, use Application.Explorers.NewExplorer event.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, October 07, 2013 6:05 AM
  • Yes, I have my Add-in displayed from 2 Outlook windows.
    Monday, October 07, 2013 6:08 AM
  • So what is the actual problem that you are experiencing? Is there a particular snippet that fails for you if more than one explorer is shown?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, October 07, 2013 6:10 AM
  • I am looking for an event handler something like an Explorer.GotFocus or an event that fires when the user selected one of the Outlook windows as the active window.

    I am also trying this one that you have mentioned "If you want to check when a particular Explorer is activated, use Explorer.Activate event". But the Explorer.Activate on my part is a method not event.


    Monday, October 07, 2013 6:26 AM
  • There is the Active method and there is the Activate event. They are completely different. When accessing the event, you need to cast the Explorer object as the particular event interface (ExplorerEvents or ExplorerEvents_10)

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by Benjamin Penn Monday, October 07, 2013 7:08 AM
    Monday, October 07, 2013 6:32 AM
  • Thanks for the help Dmitry :), below is my code:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
                this.Application.Explorers.NewExplorer += Explorers_NewExplorer;

    }

    private void Explorers_NewExplorer(Outlook.Explorer Explorer)
    {
           Outlook.ExplorerEvents_10_Event eActiveExplorer = (Outlook.ExplorerEvents_10_Event)Explorer;
           eActiveExplorer.Activate += new Outlook.ExplorerEvents_10_ActivateEventHandler(onActivateExplorer);
    }

    private void onActivateExplorer()
    {
    //do something
    }



    Monday, October 07, 2013 7:03 AM
  • Make sure the Explorer object is declared n the global (class) level to make sure it its not garbage collected.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, October 07, 2013 1:25 PM