By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,903 Members | 1,977 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,903 IT Pros & Developers. It's quick & easy.

Excel always running

P: n/a
Hello,
I'm programming an C# application which uses Automation. The problem is
when I quit the application a ghost of excel is always running (Can be
seen in all processes with th task manager). What is the solution ?
Thanks
Jan 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
KaNos,

You should make sure that even quitting the application, you set the object
to null. That would make the garbage collector do its job.

Besides that, you may have some sort of dialog opening to prevent you to
close the window. By then, use the Process.GetProcessesByName method and
kill each one of the instances.

Best,
--
Regards,
Robson Siqueira
Enterprise Architect
"KaNos" <Ka***@Isterik.comwrote in message
news:OX**************@TK2MSFTNGP05.phx.gbl...
Hello,
I'm programming an C# application which uses Automation. The problem is
when I quit the application a ghost of excel is always running (Can be
seen in all processes with th task manager). What is the solution ?
Thanks

Jan 24 '07 #2

P: n/a
You should make sure that even quitting the application, you set the object
to null. That would make the garbage collector do its job.
Not really, the GC is not aware of the unmanaged resources wrapped by the
managed resource. You need to place a strategic call to

TheExcelInstance.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(myExcel)

'this isn't strictly necessary
TheExcelInstance = Nothing

You should also note here that this may not release all instances if you
used improper programming techniquest to create the Excel object. For
instance, there may be temporary instances lying around.
"Robson Siqueira" wrote:
KaNos,

You should make sure that even quitting the application, you set the object
to null. That would make the garbage collector do its job.

Besides that, you may have some sort of dialog opening to prevent you to
close the window. By then, use the Process.GetProcessesByName method and
kill each one of the instances.

Best,
--
Regards,
Robson Siqueira
Enterprise Architect
"KaNos" <Ka***@Isterik.comwrote in message
news:OX**************@TK2MSFTNGP05.phx.gbl...
Hello,
I'm programming an C# application which uses Automation. The problem is
when I quit the application a ghost of excel is always running (Can be
seen in all processes with th task manager). What is the solution ?
Thanks


Jan 25 '07 #3

P: n/a
I am having a similiar problem where a DLL I've created calls the Interop
assembly for Excel to some COM automation.
Since the DLL I've created is loaded into a host process I have no control
over when the host process is shutdown.
Here is some sample code which illustrates what I've seen create the
orphaned Excel process.
Any help on what I'm doing wrong here would be greatly appreciated.

Sincerely
John Fors
Imports Microsoft.Office.Interop.Excel

Module ExcelConsole

Sub Main()

Dim oApp As Microsoft.Office.Interop.Excel.Application

Dim oBook As Microsoft.Office.Interop.Excel.Workbook ' = oApp.Workbooks.Add

Dim oSheet As Microsoft.Office.Interop.Excel.Worksheet '= oApp.ActiveSheet

oApp = New Microsoft.Office.Interop.Excel.Application

oApp.Workbooks.Open("C:\test\tt.xls")

oBook = oApp.ActiveWorkbook

oSheet = oApp.ActiveSheet

Debug.WriteLine(oSheet.Name)

' Debug.Print(oApp.Run("Test",25))

oApp.Visible = True

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oSheet)

Debug.Print(System.Runtime.InteropServices.Marshal .FinalReleaseComObject(oSheet))

oSheet = Nothing

oBook.Close(False)

oApp.Workbooks.Close()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oBook)

Debug.Print(System.Runtime.InteropServices.Marshal .FinalReleaseComObject(oBook))

oBook = Nothing

oApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComO bject(oApp)

Debug.Print(System.Runtime.InteropServices.Marshal .FinalReleaseComObject(oApp))

Try

oApp.Workbooks.Add()

Catch ex As Exception

Debug.WriteLine("Exception message")

End Try

oApp = Nothing

Debug.WriteLine("End Excel")

GC.Collect()

End Sub

"KaNos" <Ka***@Isterik.comwrote in message
news:OX**************@TK2MSFTNGP05.phx.gbl...
Hello,
I'm programming an C# application which uses Automation. The problem is
when I quit the application a ghost of excel is always running (Can be
seen in all processes with th task manager). What is the solution ?
Thanks

Mar 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.