-
Notifications
You must be signed in to change notification settings - Fork 1
Use IDisposable Correctly
Aaron edited this page Feb 1, 2016
·
3 revisions
Dispose() should be made safe to call multiple times
If an object's Dispose method is called more than once, the object must ignore all calls after the first one. The object must not throw an exception if its Dispose method is called multiple times. source
#region Dispose
private bool _disposed;
[ NonAction ]
void IDisposable . Dispose()
{
Dispose( true );
GC .SuppressFinalize( this );
}
protected override void Dispose( bool disposing)
{
if (_disposed)
{
return ;
}
if (disposing)
{
_context . Dispose();
}
_disposed = true ;
base .Dispose(disposing);
}
#endregion Dispose
Pages in this wiki make use of the following resources throughout
- Martin, R. C., Feathers, M. C., Ottinger, T. R., Langr, J. J., Schuchert, B. L., Grenning, J. W., Wampler, K. D., ... Coplien, J. O. (2011). Clean code: A handbook of agile software craftsmanship. Upper Saddle River [etc.: Prentice Hall.
- Lowy, Juval, (July 2011). “C# Coding Standard: Guidelines and Best Practices.” (Version 2.4) www.idesign.net, © 2011 IDesign Inc.
Resources besides these will be referenced directly where they are cited.