-
April 20th, 2009, 07:42 PM
#16
Re: Excel process remains in task manager when using OleDB
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
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.
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
April 21st, 2009, 02:37 AM
#17
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!!
-
April 21st, 2009, 05:52 AM
#18
Re: Excel process remains in task manager when using OleDB
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
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.
Last edited by JonnyPoet; April 21st, 2009 at 05:55 AM.
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
-
April 21st, 2009, 07:30 AM
#19
Re: Excel process remains in task manager when using OleDB
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!
-
April 21st, 2009, 10:14 AM
#20
Re: Excel process remains in task manager when using OleDB
It's not funny to kid the others.
The difficulty is that you have no idea how difficult it is.
.Net 3.5/VS 2008
-
August 1st, 2009, 12:16 AM
#21
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....
-
August 4th, 2009, 05:37 AM
#22
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 ??
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|