实现IDisposable接口的Dispose()方法using (R r1 = new R ()) {
r1.F();
}
或者
R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r1).Dispose();
}参考http://www.microsoft.com/china/msdn/archives/library/dndotnet/html/highperfmanagedapps.asp#highperfmanagedapps_topic8
r1.F();
}
或者
R r1 = new R();
try {
r1.F();
}
finally {
if (r1 != null) ((IDisposable)r1).Dispose();
}参考http://www.microsoft.com/china/msdn/archives/library/dndotnet/html/highperfmanagedapps.asp#highperfmanagedapps_topic8
然后实现Dispose()
他的代码如下;
/// <summary>
/// Dispose of this object's resources.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(true); // as a service to those who might inherit from us
} /// <summary>
/// Free the instance variables of this object.
/// </summary>
protected virtual void Dispose(bool disposing)
{
if (! disposing)
return; // we're being collected, so let the GC take care of this object if (dsCommand != null )
{
if (dsCommand.SelectCommand != null)
{
if( dsCommand.SelectCommand.Connection != null)
dsCommand.SelectCommand.Connection.Dispose();
dsCommand.SelectCommand.Dispose();
}
dsCommand.Dispose();
dsCommand = null;
}
}
Image img=Image.From("c:\abc.gif")
img.Flip(...);//do some operations here
img.close();
img.dispose();
File.Delete("c:\abc.gif");;//error here!请各位再帮帮忙