Disclaimer: I know IDisposable should be implemented when dealing with unmanaged resources. The rest of the code should be deterministic and do using (...) { } (equivalent of try {} finally { Dispose(); }) to guarantee a cleanup as soon as possible. Also, the GC will not call Dispose(), so the recommended pattern is to override the Fin...
I get an InvalidComObjectException after I close my application in the following piece of code:
class MyExcelManager
{
myExelAppInstance = new Excel.Application();
// finalizer
~MyExcelManager()
{
myExelAppInstance.Quit(); // InvalidComObjectException thrown here
myExelAppInstance = null;
}
}
Why is that? Shouldn't ...
Suppose I have a message pump class in C++0x like the following (note, SynchronizedQueue is a queue of function<void()> and when you call receive() on the queue and it is empty, it blocks the calling thread until there is an item to return):
class MessagePump
{
private:
bool done_;
Thread* thread_;
SynchronizedQueue queue_;...
I have a standalone .exe COM server and a trivial C# test program that launches an instance of the server and closes it immediately afterwards. Works like a charm. However, if I close the C# program itself I get an exception during the finalizer run because it is trying to unregister/unadvise COM event sinks from the no longer running CO...
In Java, finalize is called on an object (that overrides it) when it's about to be garbage collectioned, so when it's unreachable. But what if the finalizer makes the object reachable again, what happens then?
...
Based on the documentation (MSDN: link), it is clear that one should use the IDisposable pattern when implementing a finalizer.
But do you need to implement a finalizer if you implement IDisposable (so as to provide a deterministic way of disposing the object), and you dont have any unmanaged resources to clean up?
As I see it, if the ...
Hello,
I'm having trouble with a misbehaved library that throws an exception in a finalizer, which of course crashes the application.
To avoid this, I tried loading the library in its own AppDomain, but the exception still bubbles to the surface and crashes the application.
As documented on MSDN, registering to AppDomain.UnhandledExce...
So here is the story so far, I have this worker thingy which uses an AppDomain to perform some task. The domain is expensive to setup and teardown. So I create a cache per-thread of WeakReference objects to the worker thingy like so:
class Worker
{
[ThreadStatic]
static Dictionary<string, WeakReference> _workers;
public s...