If an object supports IsDisposed, this method should never throw; for many other methods, it would be useful if IsDisposed returns true, but an exception should be thrown by these methods, not IsDisposed. One could use the AssertNotDisposed utility method, which would throw out if the object was deleted, but such behavior would be expected from a method with this name.
Otherwise, I would suggest that there are many cases where it is useful to have an object containing an IDisposable and be able to delete the internal object while maintaining a useful state. For example, an object whose function is to display and maintain a modeless dialog box for receiving information from the user can usefully save a copy of the contents of the fields even after closing the box. Such an object should provide a Close method that will delete internal one-time objects, but maintain a healthy state. Although it may also have a Dispose method that will call Close, but also set the “NoLongerValid” flag, which can invoke field properties, I don't think that would really add a value.
I will give that many cases in which an object may contain a useful state after its placement indicate a class that may need to be split. For example, the Font class may need to be split into the non-transitional FontInfo class (containing the font description but not the GDI descriptor) and the IDisposable ReadyFont class (inheriting the FontInfo and encapsulating the GDI font object). Font routines can check if the object to which they were provided was FontInfo or ReadyFont; in the first case, they can create a GDI font, use it and release it; in the latter case, they can use the ReadyFont GDI font object and free it. Then the creator of ReadyFont will be responsible for ensuring that it is cleaned.
Be that as it may, I don’t know if the system will try to use the GDI object associated with the Font property of the control when rendering the control, but I know that it will not show if the font is deleted (even if it was deleted before it was assigned to font property!). The controls are certainly capable of creating new GDI fonts if necessary; I don’t know if they always create a new GDI font or if they only do it if the old one has been removed. The previous behavior would seem to be more efficient, but if it had not been encoded, it could cause problems if one thread tried to remove its font while the other thread used it.
source share