This topic has not yet been rated - Rate this topic

ChangeMonitor.NotifyOnChanged Method

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.

ExceptionCondition
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.

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

Supported in: 4.5.1, 4.5, 4

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.