Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
| Search | Today's Posts | Mark Forums Read
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 7th, 2005, 09:49 AM
Authorized User
 
Join Date: May 2005
Location: Berlin, CT, USA.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default RESOLVED - cleanup after launching Excel App

Here's my little problem:

Currently I am using a button on a windows form to transfer the contents of a datagrid into an Excel Spreadsheet and view the resulting sheet in Excel:

Each time the button is pressed during the same session (for different queries etc ) a new process instance of "EXCEL.EXE" is added to the task manager, eating up about 15 Mb of memory, even after the user has closed the Excel app. These processes go away only when the windows program is closed. Is there a way I can have my application purge these orphaned processes within the same session after the Excel app has been closed so that I don't eat up so much memory?

I have attached my button code for transfering the data and launching Excel below:

Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExport.Click
        ' display wait cursor
        Me.Cursor = Cursors.WaitCursor
        ' various variables
        Dim row As Integer
        Dim col As Integer
        Dim rowCount As Integer
        Dim colCount As Integer
        Dim cell As String
        Dim rowcell As Integer

        ' Excel Variables
        Dim excelApp As New Excel.Application
        Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add
        Dim excelWorksheet As Excel.Worksheet = _
            CType(excelBook.Worksheets(1), Excel.Worksheet)

        ' get count of rows and count of columns
        rowCount = objDataSet.Tables(0).Rows.Count()
        colCount = objDataSet.Tables(0).Columns.Count()

        ' add the column headings
        For col = 0 To colCount - 1
            row = 1
            cell = GetExcelColumn(col) & row.ToString
            excelWorksheet.Range(cell).Value = grdFieldnetData.TableStyles(0).GridColumnStyles(co l).HeaderText
            excelWorksheet.Range(cell).ColumnWidth = grdFieldnetData.TableStyles(0).GridColumnStyles(co l).Width / 4
        Next

        ' now add the data elements
        For row = 0 To rowCount - 1
            rowcell = row + 2
            For col = 0 To colCount - 1
                cell = GetExcelColumn(col) & rowcell.ToString
                excelWorksheet.Range(cell).Value = grdFieldnetData.Item(row, col).ToString()
            Next
        Next
        ' turn off wait cursor
        Me.Cursor = Cursors.Default

        ' view the spread sheet
        excelApp.Visible = True
    End Sub
 
Old June 7th, 2005, 11:50 AM
Authorized User
 
Join Date: Jun 2003
Location: Farmington, NM, USA.
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had a similar problem, only I was retrieving data from several Excel sheets. I found that when I was done with the Excel app, I had to do the following:
     xlApp.Quit()
     xlApp = Nothing
     GC.Collect()
     GC.WaitForPendingFinalizers()
Apparently, the garabage collection in this particular instance needs to be forced. Hope this helps!

=================================

She stood on the bridge at midnight,
Her lips were all aquiver.
She gave a cought,
Her leg fell off,
and floated down the river.
 
Old June 7th, 2005, 02:52 PM
Authorized User
 
Join Date: May 2005
Location: Berlin, CT, USA.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by hashtlishnii
 I had a similar problem, only I was retrieving data from several Excel sheets. I found that when I was done with the Excel app, I had to do the following:
     xlApp.Quit()
     xlApp = Nothing
     GC.Collect()
     GC.WaitForPendingFinalizers()
Apparently, the garabage collection in this particular instance needs to be forced. Hope this helps!

=================================

She stood on the bridge at midnight,
Her lips were all aquiver.
She gave a cought,
Her leg fell off,
and floated down the river.

Awesome! Many thanks, it was the garbage collection that needed to e forced :)

Thanks again for the assistance!





Similar Threads
Thread Thread Starter Forum Replies Last Post
[Resolved] GridView to Excel snufse ASP.NET 2.0 Basics 2 October 28th, 2008 02:37 PM
Using Excel Chart Object in VB App John Pennington Beginning VB 6 1 July 12th, 2006 01:39 PM
Merge Replication Metadata cleanup MSDE? dhay1999 SQL Server 2000 0 February 14th, 2005 02:52 PM
Too long cleanup.asp for extremely big reports darkov Crystal Reports 0 March 8th, 2004 07:03 AM
TempDB Size factor - Cleanup procedure happygv SQL Server 2000 5 October 7th, 2003 03:30 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.