Be cautious with WaitForPendingFinalizers. It does exactly what it says, it waits. And if something is failing to finalize then, far from curing your hang, it will cause it.
When I've been faced with excel ghosts being left behind in the task manager I've found the most important thing is to make sure all the elements in the spread sheet are properly released and they can be really hard to find because excel has an annoying tendency to create them implicitly - particularly ranges. I didn't look too closely at your code but it looks like your releasing the stuff you create explicitly but you may well be missing some implicit stuff.
Personally I avoid explicitly kicking the GC if I can. The fact that you feel the need to kick it means you're probably kicking a problem down the road. My advice would be to try removing all the GC code and watch what happens. Chances are you'll see a bunch of excel processes build up in task manager and then they'll quietly disappear about 10 seconds later.




Reply With Quote
