This project has moved. For the latest updates, please go here.
' taken from Tutorial03.vbproj
'
' This Tutorial shows you how to use the method Dipose() and DiposeChildInstances()
' for objects with active event listeners.
In case you have an object with
' exported events, a CommandBarButton for example,
and you want dispose them
' without stoppping fire events you have to use Dispose() with a parameter.
' ' See chapter1 and chapter4 in technical documentation for further info. ' Private Sub Tutorial03Main() 'Initialize Api COMObject Support LateBindingApi.Core.Factory.Initialize() ' start application Dim application As New Excel.Application() application.DisplayAlerts = False ' create new Workbook & attach close event trigger Dim book As Excel.Workbook = application.Workbooks.Add() Dim closeHandler As Excel.Workbook_BeforeCloseEventHandler =
AddressOf
Me.book_BeforeCloseEvent AddHandler book.BeforeCloseEvent, closeHandler ' we dispose the instance. the parameter false signals to api dont release
' the event listener
. set parameter to true and the event listener will
' stopped and you dont get events for the instance
' the DisposeChildInstances() method has the same method overload book.Close() book.Dispose(False) 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: Tutorial04 - Observable COM Proxy Count

Last edited Jan 5, 2012 at 10:16 AM by SebastianDotNet, version 6

Comments

No comments yet.