CacheDependency.DependencyDispose 方法
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
释放由 CacheDependency 类和从 CacheDependency 派生的所有类使用的资源。
protected:
virtual void DependencyDispose();
C#
protected virtual void DependencyDispose();
abstract member DependencyDispose : unit -> unit
override this.DependencyDispose : unit -> unit
Protected Overridable Sub DependencyDispose ()
下面的代码示例演示一个从 CacheDependency 类继承并重写 方法的 DependencyDispose 类。 调用此方法时,它会将名为 的 Disposed
自定义布尔属性设置为 true
。
VB
' 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 类的类都需要实现此方法,以清理派生类已使用的资源。
产品 | 版本 |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |