Releases all resources that are used by the current instance of the ChangeMonitor class.
Assembly: System.Runtime.Caching (in System.Runtime.Caching.dll)
The Dispose method invokes the Dispose method of derived classes only one time, the first time it is called. Subsequent calls to the Dispose method have no effect. After the method has been called, the IsDisposed property is set to true.
Before an item is inserted into the cache, it is the caller's responsibility to dispose of a ChangeMonitor instance.
After an item and its associated ChangeMonitor instances are passed to a cache, the caller must not dispose the dependency because when the Dispose method is called, the call is treated as if the dependency has changed. As a result, the OnChanged method is automatically invoked.
Taking these rules into consideration, the Dispose method must be called in one of the following ways:
Users must call the Dispose method overload if they decide not to insert the derived change-monitor instance into a cache.
The cache implementation is responsible for calling the Dispose overload if the implementation tries to insert the change-monitor instance into an object cache but the insertion fails. When the insertion attempt causes an exception, the cache implementation must dispose any associated dependencies.
If the cache entry is removed, the cache implementation must also dispose the dependency.
This automatic dispose during the event firing only occurs if the initialization of the ChangeMonitor instance previously completed.
When a derived change monitor's constructor calls the InitializationComplete method, if the state of the change monitor has already changed (that is, the state that is monitored has already changed when the constructor was still active) then InitializationComplete method will automatically dispose the change monitor.
Users should not call the Dispose method. However, you cannot prevent users from calling the method. Therefore, if they do, the OnChanged method is invoked. In that case, the cache entry is notified as if the dependency has changed.
To prevent derived classes from overriding Dispose method, the method is not an explicit interface implementation.