Considering the semantics of IDisposable, what should the Dispose do, other than cleaning the resources of course?
I saw that many classes use Dispose method to initiate shutdown processes and some other stuff, and not just doing the "resource cleanup" work. For example, if you have a thread inside the class, which needs to be shutdown, would you expect that calling Dispose gracefully shuts down this thread?
IMHO I would implement a Stop / Shutdown method on this object, and gracefully shutdown the thread there, while in the Dispose I would check when thread is still alive to simply call Abort on it (assassination style :) ).
The same example can be with timers, and all other resources which can have the some sort of termination process before finishing you work with that object.
Two examples of conflicting designs in .NET:
- ServiceBase for windows services has OnStop as well as Dispose to override.
- WebApp.Start from OWIN for self-hosting gives you back an IDisposable which I guess does the service shutdown somewhere in the Dispose process.