I have created a simple Outlook Add-in for copying contacts from one folder to another.(~5000 contacts)
Why I need this? There is a weird way for creating a public addre
Do not use any LINQ statements against Outlook collections. Or you will trap into such situations. For example:
List<Outlook.ContactItem> items = fromFolder.Items.Cast<Outlook.ContactItem>().ToList(); ;
The line of code creates a new COM object for each item in the folder simultaneously. Instead, you can iterate over all items in the folder in the for loop and release objects instantly by using the Marshal.ReleaseComObject method.
for (int i = 0; i < items.Count; i++)
{
object item = items[i];
...
Marshal.ReleaseComObject(item); item = null;
}
Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. This is particularly important if your add-in attempts to enumerate more than 256 Outlook items in a collection that is stored on a Microsoft Exchange Server. If you do not release these objects in a timely manner, you can reach the limit imposed by Exchange on the maximum number of items opened at any one time. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. Read more about that in the Systematically Releasing Objects article.