User Tools

Site Tools


dispose_template

Dispose Template

No Native Resources

// TODO: Mark class as IDisposable.
#region IDisposable Members
 
public void Dispose()
{
	Dispose(true);
	GC.SuppressFinalize(this);
}
 
protected virtual void Dispose(bool disposing)
{
	if (disposing)
	{
		// Free managed resources.
		if (managedResource != null)
		{
			managedResource.Dispose();
			managedResource = null;
		}
	}
}
 
#endregion IDisposable Members

Native Resources

// TODO: Mark class as IDisposable.
#region IDisposable Members
 
public void Dispose()
{
	Dispose(true);
	GC.SuppressFinalize(this);
}
 
~Resource() 
{
	Dispose(false);
}
 
protected virtual void Dispose(bool disposing)
{
	if (disposing)
	{
		// Free managed resources.
		if (managedResource != null)
		{
			managedResource.Dispose();
			managedResource = null;
		}
	}
	// Free native resources.
	if (nativeResource != IntPtr.Zero) 
	{
		Marshal.FreeHGlobal(nativeResource);
		nativeResource = IntPtr.Zero;
	}
}
 
#endregion IDisposable Members
dispose_template.txt · Last modified: 2016/12/31 19:05 (external edit)