Static destructor?
-
My class contains an unmanaged system object member (a user profile handle) that is initialized in the static constructor. Conversely, I need to free the object when the class (not object instances) is destroyed, but I've never heard of a static destructor. Perhaps I could use Environment.HasShutdownStarted in the finalizer, but all instances could have already been gc'd when the AppDomain unloads and the code wouldn't run. Perhaps I could use the AppDomain.Unload event to run my code. Any thoughts?
-
My class contains an unmanaged system object member (a user profile handle) that is initialized in the static constructor. Conversely, I need to free the object when the class (not object instances) is destroyed, but I've never heard of a static destructor. Perhaps I could use Environment.HasShutdownStarted in the finalizer, but all instances could have already been gc'd when the AppDomain unloads and the code wouldn't run. Perhaps I could use the AppDomain.Unload event to run my code. Any thoughts?
CBoland wrote: but I've never heard of a static destructor. They are allowable by the CLR, but I suggest using a Singleton pattern instead of static if it involves any resources. :) leppie::AllocCPArticle("Zee blog");
Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it. -
CBoland wrote: but I've never heard of a static destructor. They are allowable by the CLR, but I suggest using a Singleton pattern instead of static if it involves any resources. :) leppie::AllocCPArticle("Zee blog");
Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.