Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / March 2007

Tip: Looking for answers? Try searching our database.

Excel always running

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
KaNos - 24 Jan 2007 21:32 GMT
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
Robson Siqueira - 24 Jan 2007 21:46 GMT
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,
Signature

Regards,
Robson Siqueira
Enterprise Architect

> 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
Alvin Bruney [MVP] - 25 Jan 2007 14:06 GMT
> 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.ReleaseComObject(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.

> KaNos,
>
[quoted text clipped - 11 lines]
> > seen in all processes with th task manager). What is the solution ?
> > Thanks
John J Fors - 28 Mar 2007 18:36 GMT
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.ReleaseComObject(oSheet)

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

oSheet = Nothing

oBook.Close(False)

oApp.Workbooks.Close()

System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook)

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

oBook = Nothing

oApp.Quit()

System.Runtime.InteropServices.Marshal.ReleaseComObject(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

> 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

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.