BlockReentrancy中的ObservableCollection< T> [英] BlockReentrancy in ObservableCollection<T>

查看:170
本文介绍了BlockReentrancy中的ObservableCollection< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能有人请仁慈地向我解释什么 BlockReentrancy 法的目的是在的ObservableCollection< T>

Could someone please be kind enough to explain to me what the purpose of the BlockReentrancy Method is in the ObservableCollection<T> ?

MSDN 显示以下为例:

//The typical usage is to wrap an OnCollectionChanged call within a using scope, as in the following example:

using (BlockReentrancy())
{
    // OnCollectionChanged call
}

不过,这似乎并没有澄清,我的目的是什么。有人在乎解释?

But this doesn't seem to clarify for me what the purpose is. Anyone care to explain?

推荐答案

这是的ObservableCollection 工具 INotifyCollectionChanged ,所以它有一个 Col​​lectionChanged 事件。如果有一个用户这个事件,他们的进一步修改的集合,而集合已经在通知的过程。因为 Col​​lectionChanged 事件跟踪的究竟是什么改变,这种相互作用可能会变得非常混乱。

An ObservableCollection implements INotifyCollectionChanged and so it has a CollectionChanged event. If there is a subscriber to this event, they could further modify the collection while the collection is already in the process of notification. Since the CollectionChanged event keeps track of exactly what changed, this interaction can get very messy.

其结果是,在的ObservableCollection 允许的话,作为一个特殊的情况下, Col​​lectionChanged 事件的单个订户从它的处理程序修改集合。但它的不允许修改从 Col​​lectionChanged 处理程序集合中的如果有两个或更多的用户 Col​​lectionChanged 事件。

As a result, the ObservableCollection allows, as a special case, a single subscriber of the CollectionChanged event to modify the collection from its handler. But it disallows modifying the collection from the CollectionChanged handler if there are two or more subscribers to the CollectionChanged event.

一对方法 BlockReentrancy CheckReentancy 用来实现这个逻辑。该 BlockReentrancy 被用在 OnCollectionChanged 方法的开始和 CheckReentancy 用于修改集合中的所有方法。

The pair of methods BlockReentrancy and CheckReentancy are used to implement this logic. The BlockReentrancy is used at the start of the OnCollectionChanged method and CheckReentancy is used in all methods that modify the collection.

这篇关于BlockReentrancy中的ObservableCollection&LT; T&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆