Saving MailItem with active message in reading pane

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

Saving MailItem with active message in reading pane
 
L Thrower




Posts: 20
Joined: 2016-07-17
Hopefully, someone can point me in the correct direction.
I have a button that "tags" emails with a custom property. I then Drag the message(s) into a store where it then gets processed. Afterward, it changes the tag to inform the user that the process has been completed.

The issue I am seeing is that the "Completed" custom property isn't being saved on message that is currently open in the olPreview pane. All of the other selected messages get updated. It's just the one that is open in the reading pane.

I'm pretty sure all ComObjects are being released. Does anyone have a thought? It seems that outlook has a grasp on the message and I cannot modify it during the BeforeItemMove event.
Posted 14 Apr, 2020 16:09:53 Top
Andrei Smolin


Add-in Express team


Posts: 17367
Joined: 2006-05-11
Hello L,

You can try to experiment with Explorer.ClearSelection() and Explorer.AddToSelection() to let the email get released by Outlook. you may need to introduce a delay between these calls; check section Wait a Little; see the PDF file in the folder {Add-in Express}\Docs on your development PC.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Apr, 2020 04:37:03 Top
L Thrower




Posts: 20
Joined: 2016-07-17
Well, this may not be the most elegant solution but maybe this will help someone out in the future.
If I iterate over the messages and one or more will not save. I add the EntryID to a list. After all the mailItems have been processed I call a function and pass the failed EntryIDs. This function is in a background thread and will continuously loop until the UserProperty is set correctly.
If it fails within this new loop. I set the mailItem as IDisposable and call dispose. After I click somewhere in outlook, it updates the message as it should on the next iteration.



var dis = MailItem as IDisposable; 
dis.Dispose();
Posted 16 Apr, 2020 14:52:26 Top
Andrei Smolin


Add-in Express team


Posts: 17367
Joined: 2006-05-11
Hello L,

L Thrower writes:
I call a function and pass the failed EntryIDs. This function is in a background thread


We strongly recommended against using the Outlook object model (actually, any Office model) in a background thread. This leads to issues that hardly reproducible.

To do something asynchronously on the main thread, use the machinery we describe in section Wait a Little; see the PDF file in the folder {Add-in Express}\Docs on your development PC. The OnSendMessage even occurs on the main thread only; it is raised once Windows delivers your message (an integer > 1024) to the invisible window that Add-in Express creates for your add-in. The time between sending the message and delivering it creates the delay which is often (not always) enough to achieve your goals.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 17 Apr, 2020 03:39:46 Top