ChangeMonitor.HasChanged 属性

定义

获取一个值,该值指示由 ChangeMonitor 类监视的状态已发生更改。Gets a value that indicates that the state that is monitored by the ChangeMonitor class has changed.

public:
 property bool HasChanged { bool get(); };
public bool HasChanged { get; }
member this.HasChanged : bool
Public ReadOnly Property HasChanged As Boolean

属性值

Boolean

如果由 ChangeMonitor 实例监视的状态已发生更改,则为 true;否则为 falsetrue if the state that is monitored by the ChangeMonitor instance has changed; otherwise, false.

注解

可以在派生类中检查此属性的值 ChangeMonitor ,以查看依赖项是否已更改。You can check the value of this property in a derived ChangeMonitor class to see whether a dependency has changed.

true 依赖项发生更改时,该值将设置为 (即 OnChanged) 方法调用时。The value is set to true when a dependency change occurs (that is, when the OnChanged method is called). OnChanged派生类调用方法后, HasChanged true 无论是否 OnChangedCallback 已通过调用方法通知实例,属性的值都将为 NotifyOnChangedAfter the OnChanged method is called by the derived class, the value of the HasChanged property will be true, regardless of whether a OnChangedCallback instance has been notified by a call to the NotifyOnChanged method.

备注

调用方可以检查 HasChanged 属性,以查看依赖项是否已更改。Callers can check the HasChanged property to see whether a dependency has changed. 但在多线程环境中,更简单、更易于维护的方法是将数据插入缓存实现,而不检查 HasChanged 属性。However, in a multi-threaded environment, a simpler and more maintainable approach is to insert data into a cache implementation without checking the HasChanged property. 缓存实现必须检查 HasChanged 属性,如果已更改一个或多个关联的依赖项,则不得执行插入或设置操作。Cache implementations must check the HasChanged property for you and must not perform an insert or set operation if one or more associated dependencies have already changed.

适用于

另请参阅