NotifyDependencyChanged Method
Collapse the table of content
Expand the table of content

CacheDependency.NotifyDependencyChanged Method

Notifies the base CacheDependency object that the dependency represented by a derived CacheDependency class has changed.

Namespace: System.Web.Caching
Assembly: System.Web (in system.web.dll)

protected void NotifyDependencyChanged (
	Object sender,
	EventArgs e
)
protected void NotifyDependencyChanged (
	Object sender, 
	EventArgs e
)
protected function NotifyDependencyChanged (
	sender : Object, 
	e : EventArgs
)
Not applicable.

Parameters

sender

The source of the event.

e

An System.EventArgs object that contains the event data.

Any class that derives from the CacheDependency class must implement this method.

When you derive from the CacheDependency class, you use the base functionality of any method or property that you have not overridden. When you create an instance of the derived class, it represents the files, cache keys, database tables, or other arbitrary objects that you want to make a cached item dependent upon. When a dependency item changes, this method notifies the base functionality of the CacheDependency class that the item has changed, so that the values of the HasChanged and UtcLastModified properties can be updated.

The following code example shows a class that inherits from the CacheDependency class. It creates a public method, ResetDependency, that uses the SetUtcLastModified method to change the time at which the dependency was modified, and then calls the NotifyDependencyChanged method.

' Declare the class.
Public Class CustomCacheDependency 
   Inherits CacheDependency

     ' Constructor with no arguments 
     ' provided by CacheDependency class.
     Public Sub New()
     End Sub ' New
   
     ' Declare a Boolean field named disposedValue.
     ' This will be used by Disposed property.
     Private disposedValue As Boolean                
     
     ' Create accessors for the Disposed property.
     Public Property Disposed As Boolean
       Get
           Return disposedValue
       End Get
       Set (ByVal value As Boolean)
           disposedValue = value
       End Set
     End Property
     
     ' Create a public method that sets the latest
     ' changed time of the CustomCacheDependency
     ' and notifies the underlying CacheDependency that the 
     ' dependency has changed, even though the HasChanged
     ' property is false.
     Public Sub ResetDependency()
        If Me.HasChanged = False              
           SetUtcLastModified(DateTime.MinValue)
           NotifyDependencyChanged(Me, EventArgs.Empty)
        End If
     End Sub
     
     ' Overrides the DependencyDispose method to set the
     ' Disposed proerty to true. This method automatically
     ' notifies the underlying CacheDependency object to 
     ' release any resources associated with this class. 
     Protected Overrides Sub DependencyDispose()
        Disposed = True
     End Sub
     
     
 End Class

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2016 Microsoft