📄 nativeresourceholder.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
namespace CodeForChapter5cs
{
class NativeResourceHolder : IDisposable
{
private bool alreadyDisposed = false;
// This method does the cleanup
// gets called only from finalizer(true) OR from Dispose(false)
// protected virtual so subclasses can override it
protected virtual void Dispose(bool calledFromFinalizer)
{
if (alreadyDisposed)
{
return;
}
alreadyDisposed = true;
if (!calledFromFinalizer)
{
// if we hold other IDisposablereferences, call their Dispose method
// cannot do this from finalizer; they may have already been disposed
}
// always free native resources, e.g. handles
}
public void Dispose()
{
this.Dispose(false);
GC.SuppressFinalize(this); // get rid of finalizer!
}
~NativeResourceHolder()
{
this.Dispose(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -