Cannot dispose wrapped Excel Library object - Please Help 
Author Message
 Cannot dispose wrapped Excel Library object - Please Help

I'm calling a wrapped excel9.olb object from a component model class.  I'm
explicitly calling an overrided dispose method that is firing in the
de{*filter*}, but I still have an instance of Excel in memory.  The Excel
instance also seems to be working away for several seconds after I've
finished using it.

I'm also find zilch on how i might do this all through the VSA interface.
Any hints here would be a bonus.

I'm attaching my code for whatever its worth.  Any guidance would be much
appreciated.

Kris.

using System;

using System.ComponentModel;

using System.Configuration;

using System.Collections;

using System.Diagnostics;

using excelwrap;

namespace eOmComReport

{

/// <summary>

/// Summary description for testcomponent.

/// </summary>

public class ComReport : System.ComponentModel.Component

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

private excelwrap.Application oApp = new excelwrap.Application();

public override void Dispose()

{

if (components != null)

{

components.Dispose();

Quote:
}

base.Dispose();

//GC.SuppressFinalize(this);

Quote:
}

~ComReport()

{

Dispose();

Quote:
}

public void CreateExcelSheet(string ReportName, string SPName, string
Params)

{

string sWorkbookPath = ConfigurationSettings.AppSettings["ReportPath"];

string sWorkbookFile = sWorkbookPath + "/" + ReportName + ".xls";

//excelwrap.Application oApp = new excelwrap.Application();

oApp.Workbooks.Add(XlWBATemplate.xlWBATWorksheet);

Workbooks oWrkBooks = oApp.Workbooks;

_Workbook oWrkBook = oWrkBooks.get_Item(1);

Sheets oSheets = oWrkBook.Worksheets;

_Worksheet oWrkSheet = (_Worksheet) oSheets.get_Item(1);

oWrkSheet.Name = ReportName;

eOmFile.ManageFile.CleanupFile(sWorkbookFile);

eOmFile.ManageFile.CheckPath(sWorkbookPath);

oWrkBook.SaveAs(sWorkbookFile, XlFileFormat.xlWorkbookNormal,

null, null, null, null, XlSaveAsAccessMode.xlExclusive, null, null, null,
null);

oWrkBook.Close(null, null, null);

oWrkSheet = null;

oWrkBook = null;

oApp.Dispose();

oApp = null;

//try olb wrapper when you can.

Quote:
}

public ComReport(System.ComponentModel.IContainer container)

{

/// <summary>

/// Required for Windows.Forms Class Composition Designer support

/// </summary>

container.Add(this);

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

Quote:
}

public ComReport()

{

/// <summary>

/// Required for Windows.Forms Class Composition Designer support

/// </summary>

InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//

Quote:
}

#region Component Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

components = new System.ComponentModel.Container();

Quote:
}

#endregion
Quote:
}
}



Wed, 05 May 2004 05:36:58 GMT  
 Cannot dispose wrapped Excel Library object - Please Help

Quote:
> I'm calling a wrapped excel9.olb object from a component model class.  I'm
> explicitly calling an overrided dispose method that is firing in the
> de{*filter*}, but I still have an instance of Excel in memory.  The Excel
> instance also seems to be working away for several seconds after I've
> finished using it.

Hi,

I haven't looked at all the code, but do you call Quit() on the Excel
object?

Peter

--

Waiting for the Vengabus? http://www.*-*-*.com/
Please post all questions to the group. Thanks.



Sun, 09 May 2004 01:50:53 GMT  
 Cannot dispose wrapped Excel Library object - Please Help
Yes.

Quit, Dispose (on container and class), set to null, jump down turn around
pick a bail of cotton.

It's strange -- sometimes when I run the code for the first time the Excel
object will unload from memory -- it will still hang in memory for a couple
of seconds after the code has executed however.  Then, on the next run it
sticks around.  Very irratic.

I'm late-binding a vb6 dll right now (excel unloads with Quit()), but would
very much prefer to call a wrapped excel object from my C# class.

Any thoughts?  Thanks In advance.

Kris



Quote:


> > I'm calling a wrapped excel9.olb object from a component model class.
I'm
> > explicitly calling an overrided dispose method that is firing in the
> > de{*filter*}, but I still have an instance of Excel in memory.  The Excel
> > instance also seems to be working away for several seconds after I've
> > finished using it.

> Hi,

> I haven't looked at all the code, but do you call Quit() on the Excel
> object?

> Peter

> --

> Waiting for the Vengabus? http://www.*-*-*.com/
> Please post all questions to the group. Thanks.



Sun, 09 May 2004 21:30:19 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. disposing of all objects in object pool

2. Microsoft Excel 9.0 Object Library problem

3. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

4. To Dispose() or not to Dispose()

5. Dispose Called for Temporary Objects?

6. Managed Class Containing Unmanaged Objects Does Not Dispose

7. Need to unsubscribe from event on disposing object?

8. HELP: Cannot link direct X libraries

9. How to check the object is disposed

10. ODBC 3.0 and Excel/Text Files HELP ME PLEASE

11. Help me with vc and Excel please

12. PLEASE HELP - ODBC Excel MFC/VC6 Problem

 

 
Powered by phpBB® Forum Software