Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Do not override object.Finalize. Instead, provide a destructor

Getting the above error in following code. How to rectify it. Thanks. Please look for

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

in the below code.

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's 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 
} 
like image 720
Anuya Avatar asked Dec 18 '25 02:12

Anuya


2 Answers

Finalize() is a special method that you can't override in code. Use the destructor syntax instead:

~Kiosk() 
{ 
    Dispose(false); 
} 
like image 148
Igal Tabachnik Avatar answered Dec 20 '25 16:12

Igal Tabachnik


Do what it says. Instead of:

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

Have:

~Kiosk () 
{ 
    Dispose(false); 
} 
like image 26
Noon Silk Avatar answered Dec 20 '25 17:12

Noon Silk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!