CacheDependency.NotifyDependencyChanged(Object, EventArgs) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
通知 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
事件源。
示例
下面的代码示例演示从 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。