Why disposed object doesn't throw exception on using it after disposing?

前端 未结 6 1943
太阳男子
太阳男子 2020-12-11 15:11

Is it legal to call a method on disposed object? If yes, why?

In the following demo program, I\'ve a disposable class A (which implements IDisposa

6条回答
  •  悲&欢浪女
    2020-12-11 16:07

    The exception is not thrown because you have not designed the methods to throw ObjectDisposedException after Dispose has been called.

    The clr does not automagically know that it should throw ObjectDisposedException once Dispose is called. It's your responsibility to throw an exception if Dispose has released any resources needed for successful execution of your methods.

提交回复
热议问题