views:

58

answers:

2

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?

A: 

Have you pinpointed which line is slowing down? Create a log with time entries around some of the main methods to determine if it's (1) the web service, (2) new contact object, or (3) saving the contact.

Mike Regan
This code is run in a loop, so the same code is executed very fast at first but later on it's taking more and more to process it.
RaYell
A: 

The answer can be found here.

RaYell