|
Prev: online services
Next: clr and jit
From: Terry Holland on 6 Jul 2008 07:53 I have a vb.net app that opens an excel worksheet, reads data and then closes the sheet. Im noticing that the Excel process is still running after I have closed and disposed of my excel objects. The following code (Test1) demonstrates the essence of what I am doing. When I check the processes while ruinning the method, I notice that the Excel process remains after exiting the sub (and until I exit the application) Sub Test1 Dim objExcelApp As New Excel.Application Dim objExcelWorkBook As Excel.Workbook = objExcelApp.Workbooks.Open("C:\Test.xls") Dim objExcelWorksheet As Excel.Worksheet = objExcelWorkBook.Sheets(1) Dim objRange As Excel.Range objRange = objExcelWorksheet.Range("A1") MsgBox(objRange.Text) ''http://www.vbforums.com/archive/index.php/t-396405.html objRange = Nothing objExcelWorksheet = Nothing objExcelWorkBook.Close() objExcelWorkBook = Nothing objExcelApp.Workbooks.Close() objExcelApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) objExcelApp = Nothing End Sub When I strip the code dow to this (Test2) I notice that the process is created on line Dim objExcelApp As New Excel.Application and killed on line System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) Sub Test2 Dim objExcelApp As New Excel.Application System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) objExcelApp = Nothing End Sub What is it that is keeping a reference to the Excel process and how do I kill the process?
From: Scott M. on 6 Jul 2008 10:23 You must call ReleaseComObject(obj) on EACH COM object you've created. That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc. objects one might instantiate within the Excel.Application. "Terry Holland" <MSDNNospam248(a)nospam.nospam> wrote in message news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A(a)microsoft.com... >I have a vb.net app that opens an excel worksheet, reads data and then >closes > the sheet. Im noticing that the Excel process is still running after I > have > closed and disposed of my excel objects. > > The following code (Test1) demonstrates the essence of what I am doing. > When I check the processes while ruinning the method, I notice that the > Excel > process remains after exiting the sub (and until I exit the application) > > Sub Test1 > Dim objExcelApp As New Excel.Application > > Dim objExcelWorkBook As Excel.Workbook = > objExcelApp.Workbooks.Open("C:\Test.xls") > Dim objExcelWorksheet As Excel.Worksheet = > objExcelWorkBook.Sheets(1) > > Dim objRange As Excel.Range > objRange = objExcelWorksheet.Range("A1") > MsgBox(objRange.Text) > ''http://www.vbforums.com/archive/index.php/t-396405.html > objRange = Nothing > objExcelWorksheet = Nothing > objExcelWorkBook.Close() > objExcelWorkBook = Nothing > objExcelApp.Workbooks.Close() > objExcelApp.Quit() > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > objExcelApp = Nothing > > End Sub > > When I strip the code dow to this (Test2) I notice that the process is > created on line > Dim objExcelApp As New Excel.Application > and killed on line > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > Sub Test2 > Dim objExcelApp As New Excel.Application > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > objExcelApp = Nothing > End Sub > > > What is it that is keeping a reference to the Excel process and how do I > kill the process?
From: Terry Holland on 6 Jul 2008 18:52 Using the following as test code, the Excel process remains. Can you see a reason for this? Sub Test Dim objExcelApp As New Excel.Application Dim objExcelWorkBook As Excel.Workbook = objExcelApp.Workbooks.Open("C:\Test.xls") Dim objExcelWorksheet As Excel.Worksheet = objExcelWorkBook.Sheets(1) Dim objRange As Excel.Range objRange = objExcelWorksheet.Range("A1") MsgBox(objRange.Text) objExcelWorkBook.Close() objExcelApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(objRange) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) objRange = Nothing objExcelWorksheet = Nothing objExcelWorkBook = Nothing objExcelApp = Nothing End Sub "Scott M." wrote: > You must call ReleaseComObject(obj) on EACH COM object you've created. > > That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc. > objects one might instantiate within the Excel.Application. > > "Terry Holland" <MSDNNospam248(a)nospam.nospam> wrote in message > news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A(a)microsoft.com... > >I have a vb.net app that opens an excel worksheet, reads data and then > >closes > > the sheet. Im noticing that the Excel process is still running after I > > have > > closed and disposed of my excel objects. > > > > The following code (Test1) demonstrates the essence of what I am doing. > > When I check the processes while ruinning the method, I notice that the > > Excel > > process remains after exiting the sub (and until I exit the application) > > > > Sub Test1 > > Dim objExcelApp As New Excel.Application > > > > Dim objExcelWorkBook As Excel.Workbook = > > objExcelApp.Workbooks.Open("C:\Test.xls") > > Dim objExcelWorksheet As Excel.Worksheet = > > objExcelWorkBook.Sheets(1) > > > > Dim objRange As Excel.Range > > objRange = objExcelWorksheet.Range("A1") > > MsgBox(objRange.Text) > > ''http://www.vbforums.com/archive/index.php/t-396405.html > > objRange = Nothing > > objExcelWorksheet = Nothing > > objExcelWorkBook.Close() > > objExcelWorkBook = Nothing > > objExcelApp.Workbooks.Close() > > objExcelApp.Quit() > > > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > > > objExcelApp = Nothing > > > > End Sub > > > > When I strip the code dow to this (Test2) I notice that the process is > > created on line > > Dim objExcelApp As New Excel.Application > > and killed on line > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > > > Sub Test2 > > Dim objExcelApp As New Excel.Application > > > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > > > objExcelApp = Nothing > > End Sub > > > > > > What is it that is keeping a reference to the Excel process and how do I > > kill the process? > > >
From: Scott M. on 6 Jul 2008 20:14 Are you checking to see if Excel is running when you are debugging your code in Visual Studio? If so, you shouldn't as this isn't going to give you an accurate representation of processes. When I compile your code into an .exe and run that .exe directly with Task Manager open, Excel comes up and then drops off the list after my method call to do the Excel stuff finishes and my console sits open waiting for input via a Console.Read. -Scott "Terry Holland" <MSDNNospam248(a)nospam.nospam> wrote in message news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3(a)microsoft.com... > Using the following as test code, the Excel process remains. Can you see > a > reason for this? > > Sub Test > Dim objExcelApp As New Excel.Application > Dim objExcelWorkBook As Excel.Workbook = > objExcelApp.Workbooks.Open("C:\Test.xls") > Dim objExcelWorksheet As Excel.Worksheet = > objExcelWorkBook.Sheets(1) > Dim objRange As Excel.Range > > objRange = objExcelWorksheet.Range("A1") > MsgBox(objRange.Text) > > objExcelWorkBook.Close() > objExcelApp.Quit() > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objRange) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > objRange = Nothing > objExcelWorksheet = Nothing > objExcelWorkBook = Nothing > objExcelApp = Nothing > End Sub > "Scott M." wrote: > >> You must call ReleaseComObject(obj) on EACH COM object you've created. >> >> That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc. >> objects one might instantiate within the Excel.Application. >> >> "Terry Holland" <MSDNNospam248(a)nospam.nospam> wrote in message >> news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A(a)microsoft.com... >> >I have a vb.net app that opens an excel worksheet, reads data and then >> >closes >> > the sheet. Im noticing that the Excel process is still running after I >> > have >> > closed and disposed of my excel objects. >> > >> > The following code (Test1) demonstrates the essence of what I am doing. >> > When I check the processes while ruinning the method, I notice that the >> > Excel >> > process remains after exiting the sub (and until I exit the >> > application) >> > >> > Sub Test1 >> > Dim objExcelApp As New Excel.Application >> > >> > Dim objExcelWorkBook As Excel.Workbook = >> > objExcelApp.Workbooks.Open("C:\Test.xls") >> > Dim objExcelWorksheet As Excel.Worksheet = >> > objExcelWorkBook.Sheets(1) >> > >> > Dim objRange As Excel.Range >> > objRange = objExcelWorksheet.Range("A1") >> > MsgBox(objRange.Text) >> > ''http://www.vbforums.com/archive/index.php/t-396405.html >> > objRange = Nothing >> > objExcelWorksheet = Nothing >> > objExcelWorkBook.Close() >> > objExcelWorkBook = Nothing >> > objExcelApp.Workbooks.Close() >> > objExcelApp.Quit() >> > >> > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) >> > >> > objExcelApp = Nothing >> > >> > End Sub >> > >> > When I strip the code dow to this (Test2) I notice that the process is >> > created on line >> > Dim objExcelApp As New Excel.Application >> > and killed on line >> > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) >> > >> > Sub Test2 >> > Dim objExcelApp As New Excel.Application >> > >> > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) >> > >> > objExcelApp = Nothing >> > End Sub >> > >> > >> > What is it that is keeping a reference to the Excel process and how do >> > I >> > kill the process? >> >> >>
From: Terry Holland on 7 Jul 2008 05:54
I was doing this in debug mode. I have done as you suggested and run the compiled exe (winforms). The excel process is still running after executing the code. The process is only killed when the form is closed. I have no other code on this form other than a button_click event to execute the code. I then tried the same thing as console app as you have done and in my case the excel process is running until the console window closes Imports Microsoft.Office.Interop Module Module1 Sub Main() Dim objExcelApp As New Excel.Application Dim objExcelWorkBook As Excel.Workbook = objExcelApp.Workbooks.Open("C:\Test.xls") Dim objExcelWorksheet As Excel.Worksheet = objExcelWorkBook.Sheets(1) Dim objRange As Excel.Range objRange = objExcelWorksheet.Range("A1") Console.WriteLine(objRange.Text) 'Console.Read() objExcelWorkBook.Close() objExcelApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(objRange) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) objRange = Nothing objExcelWorksheet = Nothing objExcelWorkBook = Nothing objExcelApp = Nothing Console.WriteLine("Waiting") Console.Read() End Sub End Module "Scott M." wrote: > Are you checking to see if Excel is running when you are debugging your code > in Visual Studio? > > If so, you shouldn't as this isn't going to give you an accurate > representation of processes. When I compile your code into an .exe and run > that .exe directly with Task Manager open, Excel comes up and then drops off > the list after my method call to do the Excel stuff finishes and my console > sits open waiting for input via a Console.Read. > > -Scott > > "Terry Holland" <MSDNNospam248(a)nospam.nospam> wrote in message > news:29BA0CA5-F757-4233-B1ED-7DE4D13AC7B3(a)microsoft.com... > > Using the following as test code, the Excel process remains. Can you see > > a > > reason for this? > > > > Sub Test > > Dim objExcelApp As New Excel.Application > > Dim objExcelWorkBook As Excel.Workbook = > > objExcelApp.Workbooks.Open("C:\Test.xls") > > Dim objExcelWorksheet As Excel.Worksheet = > > objExcelWorkBook.Sheets(1) > > Dim objRange As Excel.Range > > > > objRange = objExcelWorksheet.Range("A1") > > MsgBox(objRange.Text) > > > > objExcelWorkBook.Close() > > objExcelApp.Quit() > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objRange) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorksheet) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelWorkBook) > > > > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > > > > objRange = Nothing > > objExcelWorksheet = Nothing > > objExcelWorkBook = Nothing > > objExcelApp = Nothing > > End Sub > > "Scott M." wrote: > > > >> You must call ReleaseComObject(obj) on EACH COM object you've created. > >> > >> That means on the Range, Worksheet, Workbook, Chart, PivotTable, etc. > >> objects one might instantiate within the Excel.Application. > >> > >> "Terry Holland" <MSDNNospam248(a)nospam.nospam> wrote in message > >> news:9B590AD1-E4A3-4EA8-84AA-8A0358F3673A(a)microsoft.com... > >> >I have a vb.net app that opens an excel worksheet, reads data and then > >> >closes > >> > the sheet. Im noticing that the Excel process is still running after I > >> > have > >> > closed and disposed of my excel objects. > >> > > >> > The following code (Test1) demonstrates the essence of what I am doing. > >> > When I check the processes while ruinning the method, I notice that the > >> > Excel > >> > process remains after exiting the sub (and until I exit the > >> > application) > >> > > >> > Sub Test1 > >> > Dim objExcelApp As New Excel.Application > >> > > >> > Dim objExcelWorkBook As Excel.Workbook = > >> > objExcelApp.Workbooks.Open("C:\Test.xls") > >> > Dim objExcelWorksheet As Excel.Worksheet = > >> > objExcelWorkBook.Sheets(1) > >> > > >> > Dim objRange As Excel.Range > >> > objRange = objExcelWorksheet.Range("A1") > >> > MsgBox(objRange.Text) > >> > ''http://www.vbforums.com/archive/index.php/t-396405.html > >> > objRange = Nothing > >> > objExcelWorksheet = Nothing > >> > objExcelWorkBook.Close() > >> > objExcelWorkBook = Nothing > >> > objExcelApp.Workbooks.Close() > >> > objExcelApp.Quit() > >> > > >> > > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > >> > > >> > objExcelApp = Nothing > >> > > >> > End Sub > >> > > >> > When I strip the code dow to this (Test2) I notice that the process is > >> > created on line > >> > Dim objExcelApp As New Excel.Application > >> > and killed on line > >> > > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > >> > > >> > Sub Test2 > >> > Dim objExcelApp As New Excel.Application > >> > > >> > > >> > System.Runtime.InteropServices.Marshal.ReleaseComObject(objExcelApp) > >> > > >> > objExcelApp = Nothing > >> > End Sub > >> > > >> > > >> > What is it that is keeping a reference to the Excel process and how do > >> > I > >> > kill the process? > >> > >> > >> > > > |