Replies: 1 comment
-
For graceful shutdown, it is best to do this sort of cleanup explicitly in the app main method. For non-graceful shutdown (e.g. if the application crashes with fatal error or is killed), there is no way to cleanup reliably. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So I am fiddling with a C++ library that has generated bindings for C# automatically.
To my despair, I need a reliable way to have the destructor or dispose method be called. From what I know, the calling of the destructor is not guaranteed. Lets say the application experiences an unhandled exception, a seg fault, or plain as day
Environment.Exit(int)
: how would I go about ensuring that this is handled?source
AppDomain.ProcessExit
This method will not suffice. This method only works when Environment.Exit() or maybe even Application.Exit()
source
SafeHandles Class
This method is really... odd. It's ambiguous. It may work. It may not. It's primarily for Unmanaged Windows Handles as an alternative to IntPtr. Given that people have used this class to some success as I've seen in stackoverflow.
For my use-case here, Soloud_create() that is imported returns an IntPtr and the idea I have at this moment would be to convert this into a SafeHandle.
source
CriticalFinalizerObject
This hits the nail on the hammer with what I am looking for. Its something that guarantees a class gets finalized. However, I would rather be told this is what I am looking for than to believe it. I believe my situation is entirely theoretical at the moment due to the variability of the task at hand. The idea is I let my code get marked as critical, in turn this should always get executed.
source
see also
Beta Was this translation helpful? Give feedback.
All reactions