ChangeMonitor::NotifyOnChanged Method (OnChangedCallback^)

.NET Framework (current version)
 

Called by Cache implementers to register a callback and notify an ObjectCache instance through the OnChangedCallback delegate when a dependency has changed.

Namespace:   System.Runtime.Caching
Assembly:  System.Runtime.Caching (in System.Runtime.Caching.dll)

public:
void NotifyOnChanged(
	OnChangedCallback^ onChangedCallback
)

Parameters

onChangedCallback
Type: System.Runtime.Caching::OnChangedCallback^

A reference to a method that is invoked when a dependency has changed.

Exception Condition
InvalidOperationException

The callback method has already been invoked.

ArgumentNullException

onChangedCallback is null.

Cache implementers use this method to wire themselves up to a change monitor. If you associate one or more change monitors with the cache item, you pass a CacheItemPolicy instance with a populated change monitors property to the cache item. A cache implementer that supports change monitors is responsible for iterating over the ChangeMonitors property and register the OnChangedCallback delegates with each change monitor that it finds.

Because the OnChangedCallback delegate includes an optional state parameter, a concrete change monitor implementation can pass optional state information. The cache implementer determines whether an explicit dependency on the type of state that a custom change monitor passes as part of the callback can be taken.

System_CAPS_noteNote

The base cache extensibility API has no requirement for explicit dependency on the type of state.

The implementation of the NotifyOnChanged method automatically determines whether the state of the monitor has already changed at the time NotifyOnChanged method is called. If the HasChanged property is true, then the method automatically calls the OnChangedCallback event handler, that was registered, through the OnChanged method. This occurs because it is possible that from the time a cache implementation creates a change monitor, to the time a cache implementation gets the monitor and wires itself up to it, the underlying monitored state has changed. If the state has already changed then the object that is passed to the OnChanged method is null.

The NotifyOnChanged method can be invoked only one time, and will throw an exception on subsequent calls.

Notes to Implementers:

  1. You must call the NotifyOnChanged method to be notified of any dependency changes. If a dependency change has already occurred, the OnChangedCallback instance will be called when NotifyOnChanged is called. Otherwise, the OnChangedCallback instance will be called one time, either when the OnChanged method is called or when the Dispose method is called, whichever occurs first. The OnChangedCallback instance provided by the cache implementation should remove the cache entry and if it is requested by the cache caller, raise the necessary change or update event back to the original cache caller.

  2. The object cache implementation must remove the cache entry that is associated with a dependency change.

.NET Framework
Available since 4.0
Return to top
Show: