Z
Zytan
Just as I suspected:
To be clear, you meant:
"Because *static* classes are initialized, but never finalized."
But, why aren't they? I'd like to know the reasons why, although it
is futile, since it doesn't change reality.
In Turbo Pascal, which the C# designer made, you could invoke a clean
up process on exit, which would be invoked in the 'static
constructor', and thus have a 'static destructor'. I know you can do
something like this with the DomainUnload event, and I am assuming is
much the same thing. I fear, though, it doesn't help me, since my
underlying Stream will still be finalized before it ever gets called.
I have not tested this, yet, though.
I found a hack: Make the class non-static, instantiate an instance
using a private instance c'tor within the static c'tor, thus the
finalizer will run. And I tried this, and still my Stream is
finalized before I get to poke at it. Besides, I hate hacks.
The other 'hack', which is not so much a hack, is to use the
DomainUnload event, which I haven't yet tried.
Zytan
Because classes are initialized, but never finalized.
To be clear, you meant:
"Because *static* classes are initialized, but never finalized."
But, why aren't they? I'd like to know the reasons why, although it
is futile, since it doesn't change reality.
In Turbo Pascal, which the C# designer made, you could invoke a clean
up process on exit, which would be invoked in the 'static
constructor', and thus have a 'static destructor'. I know you can do
something like this with the DomainUnload event, and I am assuming is
much the same thing. I fear, though, it doesn't help me, since my
underlying Stream will still be finalized before it ever gets called.
I have not tested this, yet, though.
No. I suggest you just flush your TextWriter after each call, and let
the OS close the handle automatically when the program exits.
I found a hack: Make the class non-static, instantiate an instance
using a private instance c'tor within the static c'tor, thus the
finalizer will run. And I tried this, and still my Stream is
finalized before I get to poke at it. Besides, I hate hacks.
The other 'hack', which is not so much a hack, is to use the
DomainUnload event, which I haven't yet tried.
Zytan