Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BetterDisposableClass : IDisposable {
- private bool disposed = false;
- public void Dispose() {
- if (disposed) return;
- CleanUpManagedResources();
- CleanUpNativeResources();
- GC.SuppressFinalize(this);
- disposed = true;
- }
- public void ImportantOperation() {
- if (disposed) throw new ObjectDisposedException();
- // ...
- }
- protected virtual void CleanUpManagedResources() {
- // ...
- }
- protected virtual void CleanUpNativeResources() {
- // ...
- }
- ~BetterDisposableClass() {
- CleanUpNativeResources();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement