在下面的代碼中獲取上述錯誤。如何糾正它。謝謝。 敬請期待錯誤:請勿重寫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
}
+1提到了一些關於爲什麼,而不是僅僅傾銷代碼。 – 2009-08-26 06:23:44
那麼,他實際上沒有提到爲什麼。異常本身表示了同樣的事情。 – 2009-08-26 06:25:33