c# - Marshal.ReleaseComObject(...) issues -
I asked to release some Excel objects after use. Is it necessary to set references to zero later (like in the following code)?
var dateCol = sheet1.get_Range ("C4", "C" + offset off); DateCol.NumberFormat = "Text"; Marshal.ReleaseComObject (dateCol); DateCol = null;
This is what I always use and it works very well
using Excel = Microsoft.Office.Interop.Excel; Excel.ApplicationClass _Excel; Excel.WorkbookWB; Excel.Worksheet WS; Try {_Excel = New Microsoft.Office.Interop.Excel.ApplicationClass (); WB = _Excel.Workbooks.Open ("FILENAME", Type Missing, Type Missing, Type Missing, Type Missing, Type Missing, Type Missing, Type Missing, Type Missing, Type Missing, Type Missing, type missing, type missing, type missing, type missing); // do something} grip (ex before) {WB.Close (wrong, type messing, type missing); throw; } Finally {GC.Collect (); GC.WaitForPendingFinalizers (); System.Runtime.InteropServices.Marshal.FinalReleaseComObject (WB); System.Runtime.InteropServices.Marshal.FinalReleaseComObject (_Excel); }
a
system.endime.interposervices. Mrishal FinierCrack Com Object
On all referenced Excel objects
Comments
Post a Comment