This project has moved and is read-only. For the latest updates, please go here.
/* taken from Tutorial03.csproj
* 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 void Tutorial03Main() { // Initialize Api COMObject Support LateBindingApi.Core.Factory.Initialize(); // start application Excel.Application application = new Excel.Application(); application.DisplayAlerts = false; // create new Workbook & attach close event trigger Excel.Workbook book = application.Workbooks.Add(); book.BeforeCloseEvent +=
Excel.Workbook_BeforeCloseEventHandler(book_BeforeCloseEvent); */ 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
* 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(this, "Done!", this.Text, MessageBoxButtons.OK,
MessageBoxIcon.Information); } void book_BeforeCloseEvent(ref bool Cancel) { }

   See next: Tutorial04 - Observable COM Proxy Count

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


No comments yet.