Error: do not override the object. Finalize. Create a destructor instead

Getting the above error in the following code. How to fix it. Thank you. please, find

protected override void Finalize() {     Dispose(false); } 

      

in the code below.

using Microsoft.Win32; 
using System.Runtime.InteropServices; 

public class Kiosk : IDisposable 
{ 

    #region "IDisposable" 

    // Implementing IDisposable since it might be possible for 
    // someone to forget to cause the unhook to occur. I didn't really 
    // see any problems with this in testing, but since the SDK says 
    // you should do it, then here a way to make sure it will happen. 

    public void Dispose() 
    { 
        Dispose(true); 
        GC.SuppressFinalize(this); 
    } 

    protected virtual void Dispose(bool disposing) 
    { 
        if (disposing) { 
        } 
        // Free other state (managed objects). 
        if (m_hookHandle != 0) { 
            UnhookWindowsHookEx(m_hookHandle); 
            m_hookHandle = 0; 
        } 
        if (m_taskManagerValue > -1) { 
            EnableTaskManager(); 
        } 
    } 

    protected override void Finalize() 
    { 
        Dispose(false); 
    } 

    #endregion 
} 

      

+2


source to share


3 answers


Do what he says. Instead:

protected override void Finalize() 
{ 
    Dispose(false); 
} 

      



There is:

~Kiosk () 
{ 
    Dispose(false); 
} 

      

+7


source


Finalize()

- a special method that cannot be overridden in code. Use the destructor syntax instead:



~Kiosk() 
{ 
    Dispose(false); 
} 

      

+11


source


In C #, the following syntax is compiled for exactly what you are trying to accomplish.

~Kiosk()
{
    Dispose(false);
}

      

+1


source







All Articles