In fact your destuctor (or finalizer in .NET speak) may not even get executed at all, at procss shutdown the runtime will only wait two seconds for all finalizers to run before it calles TerminateProcess().
This is one of the reasons I wish they had used a syntax other than destructor for a finalizer in C#. C++/CLI the successor to Managed C++ in teh next version intrduces the following syntax IIRC
class Foo
{
~Foo() {} // this generates an implementation of IDisposable
!Foo() {} // This is a finalizer
}
Regards
Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
You're destructor will get executed - just don't when! Destructors in
.NET are "non-deterministic", meaning you can't predict when they will
be executed. This is because they are called by the garbage collector
when it cleans up your object.
In fact, using destructors as your primary mechanism for doing cleanup
is NOT recommended. It's best practice to employ something called the
"IDisposable" pattern: