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該項目已變更,以便更新 和 HasChanged 屬性的值UtcLastModified。