What is the correct way of adding thread-safety to an IDisposable object?
I tend to use an integer rather than a boolean as your field for storing the disposed status, because then you can use the thread-safe Interlocked class to test if Dispose has already been called. Something like this: private int _disposeCount; public void Dispose() { if (Interlocked.Increment(ref _disposeCount) == 1) { // disposal code here … Read more