Hi.
I have a problem trying to do some file cleanup when NCrunch test process is exiting (idea is to keep a SQL CE db alive while process is alive, and delete it when process exits). I've tried both ways below but cannot get the file to be deleted, am I missing something?
What I did to test out the "cleanup" behavior was:
1) In static ctor of a fixture, create a file e.g. "e:\foo.txt"
2) in the "cleanup" methods below ("destructor" methods), delete "e:\foo.txt".
The foo.txt gets created but never deleted even though process is terminated.
http://stackoverflow.com/a/13258842
Code:
class StaticClass
{
static StaticClass() {
AppDomain.CurrentDomain.ProcessExit +=
StaticClass_Dtor;
}
static void StaticClass_Dtor(object sender, EventArgs e) {
// clean it up
}
}
and
http://stackoverflow.com/a/18709110
Code:
public static class Foo
{
private static readonly Destructor Finalise = new Destructor();
static Foo()
{
// One time only constructor.
}
private sealed class Destructor
{
~Destructor()
{
// One time only destructor.
}
}
}
Thanks.