CacheDependency.DependencyDispose 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
釋放由 CacheDependency 類別及任何衍生自 CacheDependency 的類別所使用的資源。
protected:
virtual void DependencyDispose();
protected virtual void DependencyDispose ();
abstract member DependencyDispose : unit -> unit
override this.DependencyDispose : unit -> unit
Protected Overridable Sub DependencyDispose ()
範例
下列程式代碼範例顯示繼承自 類別的 CacheDependency 類別,並覆寫 DependencyDispose 方法。 呼叫這個方法時,它會將名為 Disposed
的自訂布爾值屬性設定為 true
。
' 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 類別都必須實作這個方法,才能清除已使用衍生類別的資源。