Perhaps we should add module destructors as well? #4635
-
Since we will likely have module initializers on C#9, and the rule don't forbid the use of unmanaged resources in there, perhaps it make sense to also add "module destructors" for teardown? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Module initializer wasn't added, but exposed from C#. It requires IL having the feature first. |
Beta Was this translation helpful? Give feedback.
-
AppDomain.Unload is probably the closest we have to a module destructor. It has proven extremely unreliable in practice. If a module needs to run code during application shutdown, it needs to be a normal part of code flow and cannot be a user-defined finalizer. Otherwise in practice you'll end up with 25% success, 25% silently fails to run, 25% deadlock that leaves the process running in the background, and 25% crash. |
Beta Was this translation helpful? Give feedback.
-
I believe this is relevant here: https://devblogs.microsoft.com/oldnewthing/20120105-00/?p=8683
|
Beta Was this translation helpful? Give feedback.
I believe this is relevant here: https://devblogs.microsoft.com/oldnewthing/20120105-00/?p=8683