ItemEvents ConnectTo latency with exchange accounts

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

ItemEvents ConnectTo latency with exchange accounts
 
L Thrower




Posts: 21
Joined: 2016-07-17
Hello All,
I was hoping for some advice. We have a client using our add-in and several users who have multiple exchange mailboxes with lots of folders appear to have severe latency issues when the add-in initializes.
I have tried putting this functionality in a separate thread but the outlook UI is still very laggy.

Essentially on initialization, we loop all stores and "ConnecTo" each root folder recursively.


for (int i = 1; i <= stores.Count; i++)
	{
	try
	{                            
		_logger.LogInfo("Connecting ADX event handler to store " + stores[i].DisplayName);
		adxRibbonlblInformation.Caption = "Connecting to '" + stores[i].DisplayName + "' folders
Please wait....";
		OutlookItemsEventsClass _itemsEvents = new OutlookItemsEventsClass(this);
		_itemsEvents.ConnectTo(stores[i].GetRootFolder(), true, true);
		_logger.LogInfo("Complete");
	}
	catch (Exception ex)
	{
		_logger.LogError("Cannot connect ADX event handler to store (" + stores[i].DisplayName + "). " + ex.StackTrace);
	}
}
Posted 02 Dec, 2020 17:52:40 Top
Andrei Smolin


Add-in Express team


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

Scanning folders may be time-consuming: the more folders the longer the scan.

Using the Outlook object model on a background thread is dangerous: Office object model should be regarded as thread-unsafe.

You can create two threads that start working with calling Thread.Sleep(timeout) and continue with ADXAddinModule.SendMessage(): you start the second thread once the first one ends; when the second thread ends, you start the first one, and so on. The first thread sends a message indicating "start working", the other - "stop working". On the main thread you organize scanning the folders so that the code does the following:
- it scans the hierarchy of folders
- when the "stop working" message arrives, it lets the current step complete and saves the information required for the next step
- when the "start working" message arrives, it resumes the scan.

This scheme allows the user and your add-in work on the main thread. You can set the timeout, say, to 500 ms.

On how SendMessage works and what to pass to that method, check section Wait a little.


Andrei Smolin
Add-in Express Team Leader
Posted 03 Dec, 2020 02:40:35 Top