CacheDependency.NotifyDependencyChanged(Object, EventArgs) 方法

定义

通知 CacheDependency 基对象由派生的 CacheDependency 类表示的依赖项已更改。

protected:
 void NotifyDependencyChanged(System::Object ^ sender, EventArgs ^ e);
protected void NotifyDependencyChanged (object sender, EventArgs e);
member this.NotifyDependencyChanged : obj * EventArgs -> unit
Protected Sub NotifyDependencyChanged (sender As Object, e As EventArgs)

参数

sender
Object

事件源。

e
EventArgs

包含事件数据的 EventArgs 对象。

示例

下面的代码示例演示从 CacheDependency 类继承的类。 它创建一个公共方法 ResetDependency,该方法使用 SetUtcLastModified 方法更改修改依赖项的时间,然后调用 NotifyDependencyChanged 方法。

' Declare the class.
Public Class CustomCacheDependency 
   Inherits CacheDependency

     ' Constructor with no arguments 
     ' provided by CacheDependency class.
     Public Sub New()
     End Sub
   
     ' 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

注解

派生自 CacheDependency 类的任何类都必须实现此方法。

CacheDependency 类派生时,将使用尚未重写的任何方法或属性的基本功能。 创建派生类的实例时,它表示要使缓存项依赖的文件、缓存键、数据库表或其他任意对象。 当依赖项项发生更改时,此方法通知 类的基本CacheDependency功能该项已更改,以便可以更新 和 UtcLastModified 属性的值HasChanged

适用于

另请参阅