Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why have I not seen any implementations of IDisposable implementing concurrency?

When I look through sample implementations of IDisposable, I have not found any that are threadsafe. Why is IDisposable not implemented for thread safety? (Instead callers have a responsibility to make sure only a single thread calls Dispose()).

like image 689
dron Avatar asked Mar 14 '11 14:03

dron


1 Answers

You should not dispose of an object until you have finished with it. If there are other threads referencing the object and there is a chance they might want to call its methods, you should not be disposing of it.

Therefore it is not neccessary for Dispose to be thread safe.

like image 195
Ben Avatar answered Sep 20 '22 15:09

Ben