View Single Post
  #5  
Old May 21st 10, 06:06 PM posted to microsoft.public.outlook.program_forms
spottedmahn
external usenet poster
 
Posts: 16
Default Your server administrator has limited the number of items you

Hi Ken, thanks again for the reply.

I'm still not clear on your analysis of declaring NewCont outside the loop.
Whether I put NewCont inside or outside the loop N objects will be created.

The point of the loop is to take a Outlook Contact and create a Custom
Contact Object. Therefore for every Outlook Contact object there will be one
Custom Contact Object.

So if I have 200 Outlook Contacts in a MapiFolder the above code would
return a ListCustomContactObject whose count is 200. Make sense?

As for setting each object to null I'm unclear on how that would effect
anything. With each iteration of the loop the variables are re-assigned to
other objects.

So on Pass 1 Contact = X, then on Pass 2 Contact = Y. Nothing points to X
anymore.

I'm not trying to be combative I'm just trying to understand.

Thanks for you input,
Mike D.

"Ken Slovak - [MVP - Outlook]" wrote:

Yes, if you don't follow the advice you've seen from me and other posters
you are missing something. If you follow the advice you won't have those
problems.

Declaring the NewCont object outside the loop creates only 1 of those
objects. You just set it and reset it inside the loop. If you declare it
inside the loop and the loop executes 200 times you just created 200 of
those objects.

You can still do what you want, and then have to use
Marshal.ReleaseComObject() on each object plus setting each object to null,
then calling GC and WaitForPendingFinalizers on each pass through the loop.
That will also work, but the performance of loop execution will suffer a
lot. What I recommended is a balance of getting the loop to work and having
it work as fast as possible.

--
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

Ads