In my company the common way to release Excel Interop Objects is to use IDisposable the following way:
Public Sub Dispose() Implements IDisposable.Dispose If Not bolDisposed Then Finalize() System.GC.SuppressFinalize(Me) End If End Sub Protected Overrides Sub Finalize() _xlApp = Nothing bolDisposed = True MyBase.Finalize() End Sub
_xlApp was created in the constructor the following way:
Try _xlApp = CType(GetObject(, "Excel.Application"), Excel.Application) Catch e As Exception _xlApp = CType(CreateObject("Excel.Application"), Excel.Application) End Try
And the client uses the
using-statement to execute code concerning excel interop objects.
We completely avoid to use the two dot rule. Now I started researching how to realease (Excel) Interop Objects and almost all discussions I found about it like How to properly clean up excel interop objects or Release Excel Objects are using mostly Marshal.ReleaseComObject(), none of them using the IDisposable Interface.
My questions is: Are there any disadvantages using the IDisposable Interace for releasing excel interop objects? If so, what are these disatvantages.