Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7494739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:45:22+00:00 2026-05-29T17:45:22+00:00

I know this has been discussed earlier but I couldn’t find a satisfactory answer.

  • 0

I know this has been discussed earlier but I couldn’t find a satisfactory answer.

I have an e-mail file (.msg) which I open like below and then call Display.

oApp = new Microsoft.Office.Interop.Outlook.Application();
mail = (Microsoft.Office.Interop.Outlook.MailItem)oApp.Session.OpenSharedItem(fileName);
mail.Display(false);
oApp = null; // do I need to release this object ?

users can close it and re-open it. Before they click “reopen” I check to see if the window still exists, if yes .. then just send a SetForeground(hwnd) to that window. if Not, that means user closed it so just release the mailItem object and open again.

 public static void ReleaseCOMObject(Microsoft.Office.Interop.Outlook.MailItem item) {
        int r = System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
        while (r != 0) {
            r = System.Runtime.InteropServices.Marshal.ReleaseComObject(item);
        }
    }

If I try to open the same file again. It “sometimes” throws a “file in use exception” So, I think even though I am releasing the MailItem .. its not been released properly.

What can I do to ensure that its released properly. closing and reopening a file is a very common scenario.

Any pointers will be very helpful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:45:24+00:00Added an answer on May 29, 2026 at 5:45 pm

    If you’re using .NET’s COM-interop features (you are) then you shouldn’t need to worry about this.

    COM tracks reference counts – and when the ref count reaches 0 COM objects get released automatically – and .NET takes care of working with the standard COM reference counting mechanism for you.

    If you were P/Invoking into a C library things might be different – but you shouldn’t have any worries in a standard scenario like yours.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, I know this has been asked before but after searching I couldn't find
I know this has been discussed ad nauseum...but I have an issue with the
I know this has been discussed over and over again but I can't find
I know that this has been discused before but i cant find an answer..
I know this has been discussed a number of times but I still have
I know this topic has been discussed a lot , but I have a
I know this subject has been discussed before but still have problem with refresh
Sorry if this has been discussed before, but could nt find a suitable answer
I know IEnumerable has been discussed several times here but I couldn't find the
I know this has been discussed many times, but I am not sure I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.