I know similar questions have been asked here, but I feel like I don't understand it correctly.
I have the following code for example:
Microsoft.Office.Interop.Outlook.Explorer expl = myOutlooApplication.ActiveExplorer();
if (expl.Selection.Count > 0)
{
object selObject = expl.Selection[1];
if (selObject is Microsoft.Office.Interop.Outlook.MailItem)
{
mailItem = (selObject as Microsoft.Office.Interop.Outlook.MailItem);
this.myUserControl.MailItem = mailItem;
}
}
As you can see, the MailItem gets passed to a property of myUserControl. MyUserControl will need to access this property later to extract some information from the MailItem.
Should I Marshal.ReleaseComObject()
after passing the MailItem to myUserControl to reduce the reference counter of the RCW or is this too early?
EDIT: My problem is, that a .msg file will be opened from the file system. After closing the inspector, the user tries to open the file again, but it is locked and I am sure that the COM objects not being released properly is the cause for that.