In WPF applications, it is recommended to use
replace to prevent the potential freezing caused by parallel operations. However, in this case, another option to be considered is ConcurrentBag
. List<T>
BlockingCollection
is essentially a packaging of a collection of . It allows blocking operation until the data is available. In addition, it allows an upper limit to the number of storage elements.
BlockingCollection
IProducerConsumerCollection<T>
and to create a blocking concurrent package. The key difference between standard and is to remove the obstruction of the attempt and the enforcement of the upper limit of the element.
However, in the given scenario, there is no need to block or the upper limit for enforcement. Therefore, using in this case will add a layer of unnecessary and unused function. ConcurrentBag<T>
BlockingCollection
Conclusion IProducerConsumerCollection<T>
BlockingCollection
replace BlockingCollection
to solve the potential scene of potential frozen in parallel WPF operation. It is not the most suitable option.
The above is the detailed content of BlockingCollection vs. ConcurrentBag in Parallel WPF Applications: Which Collection Should I Use?. For more information, please follow other related articles on the PHP Chinese website!