Rewrite Finalize method

zhaozj2021-02-16  51

The Finalize method is not allowed to clean up resources in the event of an unable to call the Dispose method. You should only implement the Finalize method to clean up the unmanaged resources.

The range of Object.Finalize method is protected. You should maintain this limited range when rewriting the method in the class.

You cannot call or rewrite the Object.Finalize method from a managed extension of C # or C programming languages. C # and hosted extensions provide destructor as a mechanism to write termination code. In C # and hosted extensions, you must use the patterned syntax to perform the cleaning operation. Since the syntax is implicitly invoke the Finalize method for the object base class, it is easy to use. This ensures that Finalize is called for all levels of the current class from it from its export. The following code example is written for the destructor. ~ Myclass () {// Perform Some Cleanup Operations Here.} This code is implicitly translated into the following code. Protected Override Void Finalize () {Try {// Perform Some Cleanup Operations Here.} Finally {base.Finalize ();}}

转载请注明原文地址:https://www.9cbs.com/read-21171.html

New Post(0)