Apuhjee


The following code cruises through the first few hundred records, but then hits a snails pace. Does anyone know why this may be or how it might be optimized for better performance (btw: this is running on a good processor w/ 2 gig RAM)

Outlook.MAPIFolder contacts =
(Outlook.
MAPIFolder)this.ActiveExplorer().Session.
GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.
MAPIFolder businessContacts =
contacts.Folders["Existing Business Contacts"];
Outlook.
ContactItem contact;

SalesContactsTableAdapter ta = new SalesContactsTableAdapter();
SalesContactsDataSet ds = new SalesContactsDataSet
();
ta.Fill(ds.SalesContacts);

foreach (SalesContactsDataSet.SalesContactsRow row in ds.SalesContacts)
{
contact =
(Outlook.
ContactItem)this.CreateItem(Outlook.OlItemType
.olContactItem);
contact.CustomerID = row.ContactId.ToString();
contact.Title = row.Title1;
contact.FirstName = row.FirstName1;
contact.LastName = row.LastName1;
contact.Suffix = row.Suffix1;
contact.JobTitle = row.PositionHeld1;
contact.Email1Address = row.Email1;
contact.CompanyName = row.CompanyName;

contact.Save();
contact.Move(businessContacts);
}

Cheers ~ jp



Re: Visual Studio Tools for Office Bulk Item Creation and Performance (or lack of...)

Phil Hoff - MSFT

I see similar behavior on my machine after a thousand items or so. After some experimentation, I was able to keep a flat item creation rate (at least through 5000 items) by forcing a garbage collection every 100 items. You might try something similar. For example:

int i = 0;

foreach (...row in dataset...)

{

// Add item

i++;

if (i % 100 == 0)

{

GC.Collect();

}

}

It may be that you're creating items (which are really just wrapped COM objects) far faster than the GC is freeing them and the management overhead accumulates to the point where it impacts the creation of new items. On the other hand, I'm not a CLR expert so you might get a more accurate answer on a CLR-specific forum.

-Phil