I'm working on a Outlook 2007 AddIn using VSTO and one of the things my addin is supposed to do is to import contacts using web service.
The algorithm for that is very simple: it asks web service for a list of identifiers of items that needs to be synchronized and then it fetches them and saves in Outlook.
The problem happens when I have to synchronize large number of records (a 1000 for example). At first it's pretty fast synchronizing 100 records in like 15 seconds, but the more records it gets the slower it is. After fetching 900 records it needs around a minute and half to fetch last 100.
I'm pretty sure that's not the problem of my code because it's just very simple (something like this):
foreach (int i in idCollection) {
Contact c = service.GetContact(i);
Outlook.Contact contact = (Outlook.ContactItem)ThisAddIn.Application.
CreateItem(Outlook.OlItemType.olContactItem);
contact.FirstName = c.Name;
// set few more fields like this
contact.Save();
}
One solution I think of is that Outlook may be indexing contacts and it needs to rebuild the index after new element is created. Since I'm creating new elements all the time it needs to rebuild index very often and also it has to index more and more items and that might slow it down. But that's only a guess. I didn't find any conformation on that in MSDN.
Does anyone knows how to solve this problem?