Re: Excel process remains in task manager when using OleDB
Quote:
Originally Posted by
jasonli
At the end of program, after everything is done, use Process class to check running process list and find excel to kill it. How do users know that excel application doesn't terminate correctly?
In my program I open excel file and save data in it, just can't terminate the process. It just stays in process list, like a ghost. Very annoying!
My way is just a workaround.
How can you be sure it is that excel process started by your code. ? Very dangerous workaround.
It easily can happen that one wants to terminate your program just while he is doing some other work just in an excel file.
He closes your application and his work in the excel application is also shut down ( withut storing his work in before as it was simple killed :sick:
Happy Sunday my dear. No sorry, this is impossible. Two possibilities: A) We have to find why it doesn't correctly close or
b) dont use excel for this job.
Re: Excel process remains in task manager when using OleDB
I finally managed to solve the problem. I used subroutines for opening, saving and checking the excel file and this fixed the problem. I can't explain why, but as long as this works it's fine by me!!
Re: Excel process remains in task manager when using OleDB
Quote:
Originally Posted by
goisve
I finally managed to solve the problem. I used subroutines for opening, saving and checking the excel file and this fixed the problem. I can't explain why, but as long as this works it's fine by me!!
;) Wasn't this what I suggested ? Look here :) post #6
Quote:
Originally Posted by JonnyPoet
b) If you cannot avoid to use one of them then use small subroutines where you only do the specific needed actions for example one subroutine to open the application, another one to use the worksheets .. use the needed try - catch routines in this subroutines so you can differentiate between cases where the application for any reason wan't opened and cases where you didn't get access to the needed Worksheet, because the problems I have seen in my applications had been that there had been for examples problems anywhere in the code so an error disables to d what was wanted to do and in such cases the application wasn't closed properly so it (Excel.exe) remains in the process List. Thus then created additional problems when trying to execute the application again.
Handling in steps corrected the issue as for example: failed to open.... unnecessary to close. But all this IMHO needs a very well arranged exceptions handling.
Great you have got it working without some strange workarounds.
Re: Excel process remains in task manager when using OleDB
Quote:
Originally Posted by
JonnyPoet
;) Wasn't this what I suggested ? Look here :) post #6Great you have got it working without some strange workarounds.
Yes, Jonny your post really helped me out and I 'm grateful for that. Sorry I forgot to mention it!
Re: Excel process remains in task manager when using OleDB
It's not funny to kid the others.
Re: Excel process remains in task manager when using OleDB
Nice post....
Thanks to all for the work-arounds...
But I have tried to kill the Excel application right after using it...
And it worked amazingly...!!!
My code is in VB.net.... but you can try the same in C# as well....
Dim wBook As Excel._Workbook = Nothing
Try
wBook = GetObject(path)
'in c# use [wBook = System.Runtime.InteropServices.Marshal.BindToMoniker(path)]
'write code to manipulate the WorkBook
Catch ex As Exception
Throw ex
Finally
If Not wBook Is Nothing Then
For Each wSheet As Excel.Worksheet In wBook.Worksheets
System.Runtime.InteropServices.Marshal.ReleaseComObject(wSheet)
Next
wBook.Close()
While System.Runtime.InteropServices.Marshal.ReleaseComObject(wBook) > 0
End While
wBook = Nothing
End If
End Try
The only trick is....
I have used the interface Excel._WorkBook instead of Excel.WorkBook.
You can try....
Re: Excel process remains in task manager when using OleDB
Trying to kill the Excel process isn't a safe method. what is the gurantee that you are killing the exact excel application you had instantiated , there might be chance that you end up killing some one else's excel application . Isn't it ??