Редагувати

Поділитися через


ChangeMonitor.NotifyOnChanged(OnChangedCallback) Method

Definition

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

public:
 void NotifyOnChanged(System::Runtime::Caching::OnChangedCallback ^ onChangedCallback);
public void NotifyOnChanged (System.Runtime.Caching.OnChangedCallback onChangedCallback);
member this.NotifyOnChanged : System.Runtime.Caching.OnChangedCallback -> unit
Public Sub NotifyOnChanged (onChangedCallback As OnChangedCallback)

Parameters

onChangedCallback
OnChangedCallback

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

Exceptions

The callback method has already been invoked.

onChangedCallback is null.

Remarks

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.

Note

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 Inheritors

  1. You must call the NotifyOnChanged(OnChangedCallback) method to be notified of any dependency changes. If a dependency change has already occurred, the OnChangedCallback instance will be called when NotifyOnChanged(OnChangedCallback) is called. Otherwise, the OnChangedCallback instance will be called one time, either when the OnChanged(Object) 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.

Applies to

See also