November 16, 2009 .NET
November 16, 2009 .NET
Running FxCop on some old stuff code gives me next error: “Implement IDisposable Correctly”.
And provided me with link to MSDN: http://msdn2.microsoft.com/ms244737(VS.90).aspx
I took look at existing code and it looked like:
And here are lot of incorrect implementation of the IDisposable.
At first I added GC.SuppressFinalize(this); like here:
Of course it was not enough – it is needed to call Dispose(true) because my class is not sealed.
You also need to have re-overridden Finalize.
So code which passed FxCop verification looks like:
Please go to MSDN page and read it, since to know how to implement IDisposable correctly is important thing.
code
more code
~~~~