Add-in startup code freezes when using send-to from Windows Explorer

Add-in Express™ Support Service
That's what is more important than anything else

Add-in startup code freezes when using send-to from Windows Explorer
 
Aaron Robertson-Hodder




Posts: 27
Joined: 2009-05-25
Hi

We recently became aware of an issue affecting one of our products that uses Add-in Express in Outlook. The issue was reported in Outlook 2010 however we can also reproduce the symptoms in Outlook 2016. The problem manifests when using Windows Send To > Mail Recipient and occurs when Outlook isn?Â?Ð?ét already running.

Our add-in startup code doesn?Â?Ð?ét complete and appears to get suspended or frozen by Outlook until the user dismisses the window ?Â?Ð?ã at which time the startup logic completes when Outlook is shutting down. This issue also appears to have an impact on other add-ins. Add-ins loaded after our add-in don?Â?Ð?ét have their startup code executed until the new mail inspector window is dismissed.

We can reproduce this issue by creating a very basic Add-in Express add-in that displays two messageboxes on startup. When starting Outlook normally both messageboxes appear in succession as expected. However when starting Outlook via Send To > Mail Recipient only the first messagebox is displayed until the user dismisses the Outlook inspector window at which time the second messagebox is displayed. Attaching a debugger shows the code is waiting to execute and that it continues only when the window is dismissed.

The issue can be demonstrated with the following code:

public AddinModule()
{
InitializeComponent();
AddinStartupComplete += AddinModule_AddinStartupComplete;
}

private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
{
System.Windows.MessageBox.Show("Startup");
System.Windows.MessageBox.Show("Startup 2");
}

This behaviour does not occur when using a VSTO Outlook add-in:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{

System.Windows.MessageBox.Show("Startup VSTO");
System.Windows.MessageBox.Show("Startup VSTO 2");
}

It seems to be related to the Window message loop but only triggered when the add-in is loaded by Add-in Express. Could you please advise a solution or workaround?

Thanks
Posted 21 Sep, 2016 06:23:02 Top
Andrei Smolin


Add-in Express team


Posts: 18844
Joined: 2006-05-11
Hello Aaron,

An Add-in Express based add-in gets loaded in a slightly different moment. You can use the SendMessage/OnSendMessage trick to get two messages shown; see section Wait a Little at https://www.add-in-express.com/docs/net-office-tips.php#wait-a-little. That is, in the AddinStartupComplete event, you call SendMessage and show the message boxes when the OnSendMessage event occurs.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Sep, 2016 07:35:54 Top
Aaron Robertson-Hodder




Posts: 27
Joined: 2009-05-25
Hi Andrei

Thanks for your reply.

I think perhaps my example was a little misleading. It certainly triggers the issue however our production code isn't actually displaying MessageBoxes or any other UI during startup.

What it does do is call a WCF endpoint, which also results in the same behaviour when using Windows Send To > Mail Recipient.

I updated the sample code as follows:

        public AddinModule()
        {
            InitializeComponent();
            AddinStartupComplete += AddinModule_AddinStartupComplete;
        }

        private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
        {
            var client = new ServiceReference1.CBAgentServiceClient();
            var ready = client.CheckReady();
            client.Abort();

            client = new ServiceReference1.CBAgentServiceClient();
            ready = client.CheckReady();
            client.Abort();
        }


The CheckReady() method on the WCF service simply returns a Boolean value via a named pipe binding, so you could create your own service in order to see the issue yourself. The second CheckReady() request becomes frozen until after the Outlook inspector window displayed by Send To > Mail Recipient is dismissed.

As mentioned, this behaviour does not occur if Outlook is already running or when implemented in a standard VSTO add-in. We believe this issue is due to the way in which Add-in Express is processing window messages.

Could you please confirm that you can reproduce this issue and also advise a resolution?

Thanks
Posted 21 Sep, 2016 22:59:38 Top
Andrei Smolin


Add-in Express team


Posts: 18844
Joined: 2006-05-11
Hello Aaron,

private void AddinModule_AddinStartupComplete(object sender, EventArgs e)
{
    ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
    var ready = client.GetData("");
    client.Abort();
    System.Diagnostics.Debug.WriteLine("!!! 1");

    client = new ServiceReference1.Service1Client();
    ready = client.GetData("");
    client.Abort();
    System.Diagnostics.Debug.WriteLine("!!! 2");
}


I've created a WCF service and used the code above in the Outlook add-in. In my case, the order of events is this:
- Outlook 2016 32bit is closed
- In Windows Explorer, I right-click a file and choose Send To | Mail Recipient on the context menu
- A new Outlook mail item gets opened in an Outlook Inspector window; the file is attached to the email
- I close the inspector window
- Two debug messages from the AddinStartupComplete event fire


Andrei Smolin
Add-in Express Team Leader
Posted 23 Sep, 2016 01:25:40 Top
Aaron Robertson-Hodder




Posts: 27
Joined: 2009-05-25
Hi Andrei

It seems you have reproduced the issue. Your debug messages should fire before the Outlook inspector window opens, not when it is closed.

If you pause the debugger before closing the inspector window you'll see the code is blocking on the WCF request and it does not continue until the window is closed.

In our case we need to make WCF requests on startup and this behaviour is a major issue. As previously mentioned it behaves correctly when using a VSTO add-in so Add-in Express appears to be causing the issue.

How can we get a resolution to this problem?

Thanks,

Aaron
Posted 11 Oct, 2016 23:59:46 Top
Andrei Smolin


Add-in Express team


Posts: 18844
Joined: 2006-05-11
Hello Aaron,

In the upcoming release of Add-in Express of Office and .NET, we are going to provide a way for you to learn when the Application object is assigned to the HostApplication property of the add-in module. I suppose this will let you handle this scenario.


Andrei Smolin
Add-in Express Team Leader
Posted 17 Oct, 2016 06:25:51 Top