This project has moved and is read-only. For the latest updates, please go here.
' taken from Tutorial01.vbproj
' All objects in NetOffice which are based on CoClasses or Interfaces are wrapping 
' COM Proxies.
It's necessary to release a created COM Proxy by the client caller. ' This tells the COM Server (meaning your office application) that you do not need
' the instance any longer.
' In the MS Interop Assemblies you do that with Marshal.ReleaseComObject(object proxy) ' In NetOffice any object has the Method Dispose() to do that. ' An implemented Proxy Table in NetOffice makes it possible that you do not have
' to call Dispose() for any (implicitly) created object.
' This examples shows you how to use the Dispose() method to release an object
' and its created child objects.
' ' See chapter1 and chapter5 in technical documentation for further info. ' Private Sub Tutorial01Main() ' NetOffice manages COM Proxies for you to avoid any kind of memory leaks ' and make sure your application instance removes from process list if you
' want.
' Initialize Api COMObject Support LateBindingApi.Core.Factory.Initialize() ' start application Dim application As New Excel.Application() application.DisplayAlerts = False Dim book As Excel.Workbook = application.Workbooks.Add() ' now we have 2 new COM Proxies created. ' ' the first proxy was created while accessing the Workbooks collection
' from application
. the second proxy was created by the Add() method from
' Workbooks and stored now in book
with the application object we have
' 3 created proxies now. the workbooks proxy was created
about application
' and the book proxy was created about the workbooks.
' NetOffice holds the proxies now in a list as follows: ' ' Application ' + Workbooks ' + Workbook ' ' any object in NetOffice implements the IDisposible Interface. ' use the Dispose() Method to release an object. the method release all
' created child proxies too.
application.Quit() application.Dispose() ' the application object is ouer root object ' dispose them release himself and any childs of application, in this
' case workbooks and workbook
' the excel instance are now removed from process list MessageBox.Show(Me, "Done!", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information) End Sub

   See next: Tutorial02 - Efficient using Dispose & DisposeChildInstances

Last edited Jan 5, 2012 at 10:58 AM by SebastianDotNet, version 9


No comments yet.