Declare NewCont outside the loop so you aren't creating an instance of it
each pass through the loop. Set both contact objects to null, if that's not
enough to prevent the error then call Marshal.ReleaseComObject() on them. If
that's not enough then call the GC and WaitForPendingFinalizers(). Do it in
steps so you don't add more handling than the minimum needed. Using
ReleaseComObject() and the garbage collection is expensive.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
"spottedmahn" wrote in message
...
I'm receiving the following COMException:
"Your server administrator has limited the number of items you can open
simultaneously. Try closing messages you have opened or removing
attachments
and images from unsent messages you are composing."
when I try to iterate thru a list of Contact Items.
I've read a few posts on this same error message but I'm still unsure how
of
how to properly fix it.
Here is my code:
ListContactItem Results = new ListContactItem();
Outlook.Items Contacts = this.WcmsContactsMapiFolder.Items;
Outlook.ContactItem Contact = (Outlook.ContactItem)
Contacts.GetFirst();
do
{
ContactItem NewCont =
ContactItem.FromOutlookContactItem(Contact, this.SifApp);
Results.Add(NewCont);
Marshal.ReleaseComObject(Contact);
Contact = (Outlook.ContactItem)Contacts.GetNext();
} while (Contact != null);
return Results;
I've read posts that say you must call " Marshal.ReleaseComObject()" but
that doesn't appear to be closing the connection.
I've read posts that say to increase the simultaneous connection limit but
that doesn't see right to me. I'm able to view the contact list in
Outlook
so it is reading it somehow.