Do ADXOutlookItemEvents hold exclusive access to connected items?

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

Do ADXOutlookItemEvents hold exclusive access to connected items?
I'm having weird behaviour when using ADXOutlookItemEvents 
Horatiu Muresan


Guest


Hello,

I'm experiencing some issues when using the said class, I'm connecting to appointment items using the ConnectTo(object olItem, bool eventClassReleasesComObject) method so that I can do specific actions during certain events like ProcessSend, ProcessWrite etc.

The issues I noticed are:
1. Update emails to participants are sent only after restarting Outlook, sometimes they aren't sent at all and get stuck in the Outbox folder.
2. I have Google Sync extension installed, seems that if the sync occurs during the time in which the appointment item has the event listener(ADXOutlookItemEvents) attached(so before the RemoveConnection() method was called), the sync with google fails for that appointment

A few details on the context:
- I connect the event listeners both when using drag and drop in the outlook calendar tab on ExplorerSelectionChanged and when opening the inspector on InspectorActivate
- Reproduced both with Outlook 2013 and 2016
- With the com extension disabled, those issues do not occur so it's definitely something related to it.

Do you have any idea why the above might happen? Any advice is more than welcomed. Thank you!

Horatiu
Posted 09 May, 2016 09:10:18 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Horatiu,

The ADXOutlookItemEvents class does not "hold exclusive access" to an Outlook item, this class is just a wrapper that connects to events of an Outlook item. For testing purposes, you can try to use, e.g. the
https://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.appointmentitemclass.aspx class instead of ADXOutlookItemEvents. Do you see the same issues in this case?

Also, I would suggest that you make sure your code properly releases Outlook COM objects, this may lead to such issues too.
Posted 11 May, 2016 05:28:46 Top
Horatiu Muresan


Guest


I'm doing two bare-bone test add-ins one using ADXOutlookItemEvents class the other using AppointmentItemClass which you suggested, hopefully it will work with the latter.

Will let you know.

Thank you for your suggestion,
Horatiu
Posted 12 May, 2016 03:07:08 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Horatiu,

Please don't forget to check your code for unreleased COM objects. It is also a frequent cause of problems.
Posted 12 May, 2016 04:37:23 Top
Horatiu Muresan


Guest


Hi Dmitry,

Yes, it might be related actually.

Question is, while a COM object(an AppointmentItem in my case) is referenced (has refcount > 0) it is not accessible in the unmanaged code, or in other com add-ins which might be installed in Outlook?

One of the workflows in my case is that I use the .ConnectTo(appointmentItem, true) method of ADXOutlookItemEvents on InspectorActivate event so that I can track the ProcessSend, ProcessWrite, ProcessDelete etc events, and .RemoveConnection() method on InspectorClosing event. My guess is that during the time the given Inspector is active(thus the AppointmentItem has refcount > 0) any attempts to access this AppointmentItem elsewhere(be it in the unmanaged code or by other Com Addins) fail- thus Google Sync add-in fails to update the google servers and the update invitations getting stuck in the outbox.

Is this a possible cause? If so, I think the solution would be to try to keep the AppointmentItem referenced for as short as possible amount of time each time I need it.


Thank you,
Horatiu
Posted 12 May, 2016 08:08:16 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Horatiu,

Question is, while a COM object(an AppointmentItem in my case) is referenced (has refcount > 0) it is not accessible in the unmanaged code, or in other com add-ins which might be installed in Outlook?


I have just tried to emulate this scenario. For this, I created a small Outlook add-in, and handled the InspectorActivate and InspectorClose events. In InspectorActivate, I created the AddinExpress.MSO.ADXOutlookItemEvents class and called ConnectTo; in InspectorClose, I called RemoveConnection and Dispose.

Then, I registered my test add-in, opened an appointment item from my calendar, opened the VBA editor (Alt+F11), wrote and executed the following macro:

Public Sub ChangeBody()

    Application.ActiveInspector.CurrentItem.Body = "test body"

End Sub


I see that the body of the open appointment item was changed without any problems. I can send you my test add-in if you wish.

You can try to emulate the same scenario by using two add-ins. I think everything should work properly. If you manage to reproduce the problems by using 2 add-ins, please send them to me for testing.
Posted 12 May, 2016 10:54:50 Top
Horatiu Muresan


Guest


Yes please send your plugin to my email address listed on the site so that I can compare and see if i can repro the issue with it.

Thank you for all the help so far,
Horatiu
Posted 12 May, 2016 11:41:25 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Horatiu,

I have just sent my test project to you.
Posted 13 May, 2016 03:46:28 Top
Horatiu Muresan


Guest


Hi again Dmitry,

The add-in you sent works as expected, added connecting to items on Explorer's Selection changed and Explorer activate events and I could not reproduce the Google App sync issue.

We use a slightly different implementation,I'm sending a bare-bone sample of our code which reproduces the issue I was describing(as reply to your email with the sample). I'm almost out of ideas on what it's causing it, can you please have a look over it and see if there's something obviously wrong with it? What happens is that after a few drag and drops and resizes of the events in the outlook calendar the google sync(usually with more than 1 event) fails and the two calendars go out of sync on the newly created event(s).

The Outlook add-in we use for syncing with Google is :
https://tools.google.com/dlpage/gappssync


Thank you again for everything,
Horatiu
Posted 20 May, 2016 06:30:18 Top