The correct way to implement IDisposable

So I’m behind in my blogging… Lately, and in the coming weeks, I am working on the new version of our framework at work – so I’m hip-deep in coding. One of the great things about doing component development instead of application development, is the quality standard must be set higher, and you’re also sort of forced to figure out the proper way to do things, or else it will come back to bite you!
Earlier this week, I was finishing this wrapper for IBM MQ access, and I needed to implement IDisposable in my class, to make sure to close down the MQ connection properly. Well, it wasn’t getting called all the time. So when I was researching on why, it turns out there is a proper pattern for implementing IDisposable. See here:
Implementing a Dispose method
When I implemented it this way (and made it thread-safe) – it’s getting called every time now! I’m not perfectly clear on why there is a SECOND overload for Dispose(), but I don’t really have time to dig into it further. This pattern seems to work, consistently.
The point is, don’t go implementing IDisposable all willy-nilly – do it the proper way, as described in the link above!!
Posted in Best-practices, Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: