错误:不要覆盖 object.Finalize。相反,提供一个析构函数
在以下代码中出现上述错误。如何纠正它。谢谢。 查找。
protected override void Finalize() { Dispose(false); }
请在下面的代码中
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
}
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Finalize()
是一种特殊方法,您无法在代码中重写。请改用析构函数语法:Finalize()
is a special method that you can't override in code. Use the destructor syntax instead:按它说的去做。而不是:
有:
Do what it says. Instead of:
Have:
在 C# 中,以下语法将完全编译为您想要完成的任务。
In C#, the following syntax compiles to exactly what you're trying to accomplish.