C# - How do I properly clean com objects?

By [)ia6l0 iii

The ReleaseComObject method from the Marshal class helps you interact with unmanaged code.

The ReleaseComObject method from the Marshal class helps you interact with unmanaged code.

The following code sample shows you how to use it.

private void COMCleanUp(object o)
{
    try { System.Runtime.InteropServices.Marshal.ReleaseComObject(o); }
    catch {}
    finally { o = null; }
}

Related FAQs

Use the Environment class to get important and user-specific properties like the User Profile folder.
There is no File.Rename method in C#. Use the System.IO.File.Move method instead.
Extension method to get the start of a day
Use the GetCommandLineArgs static method of the Environment class. It returns an array of the arguments.
You can truncate the file paths using the Shell LightWeight library.
Extension method to get the elasped time
C# - How do I properly clean com objects?  (1523 Views)