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。