WPF(.NET 4.0)内部错误消息:哈希表插入失败.负载系数太高 [英] Frustrating error in WPF (.NET 4.0) internals: Hashtable insert failed. Load factor too high

查看:269
本文介绍了WPF(.NET 4.0)内部错误消息:哈希表插入失败.负载系数太高的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了自定义的规则引擎,其中该引擎的每个元素都是DependencyObject类的后代,因此可以在XAML中对其进行描述,包括对依赖项属性,标记扩展,绑定等的支持. 此规则引擎的目的是处理作为输入而来的某些信息,并将输出信息返回给队列. 整个对象树在单个线程中被实例化一次(从XAML),并且一系列Input对象正在从Input队列中进行处理. 一切正常,直到我增加线程数-有时(并非总是如此!)它会引发以下异常:

I have built custom Rules Engine, where each element of this engine is a descendant of DependencyObject class, so that it could be described in XAML including support for dependency properties, markup extensions, bindings, and so on. The purpose of this Rules Engine is to process certain information which comes as an input and to return the output information back to the queue. The entire tree of object is being instantiated once (from XAML) in a single thread and the series of Input objects are being processed from the Input queue. All works fine until I increase the number of threads - sometimes (not always!) it throws the following exception:

    System.InvalidOperationException: Hashtable insert failed. Load factor too high. The most common cause is multiple threads writing to the Hashtable simultaneously.
       at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
       at MS.Internal.Data.ValueChangedEventManager.PrivateAddListener(Object source, IWeakEventListener listener, PropertyDescriptor pd)
       at MS.Internal.Data.PropertyPathWorker.ReplaceItem(Int32 k, Object newO, Object parent)
       at MS.Internal.Data.PropertyPathWorker.UpdateSourceValueState(Int32 k, ICollectionView collectionView, Object newValue, Boolean isASubPropertyChange)
       at MS.Internal.Data.PropertyPathWorker.OnDependencyPropertyChanged(DependencyObject d, DependencyProperty dp, Boolean isASubPropertyChange)
       at System.Windows.Data.BindingExpression.HandlePropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
       at System.Windows.Data.BindingExpressionBase.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
       at System.Windows.Data.BindingExpression.OnPropertyInvalidation(DependencyObject d, DependencyPropertyChangedEventArgs args)
       at System.Windows.DependentList.InvalidateDependents(DependencyObject source, DependencyPropertyChangedEventArgs sourceArgs)
       at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
       at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
       at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
       at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
...

所以我想知道,这是WPF内部的一个错误还是我必须仔细研究一下我的代码?有人遇到过这样的问题吗? 由于我不使用任何可能相互干扰的全局线程不安全对象,因此我希望DependencyObject在多线程环境中可以正常工作,对吗?

So I wonder, is this a bug in WPF internals or I have to take a closer look at my code? Has anyone experienced such problem before? Since I don't use any global thread-unsafe objects that may interfere with each other, I expect DependencyObject to work correctly in multi-threaded environment, correct?

推荐答案

尝试在每次写入时使用lock()语句,以确保您的写入操作不会同时发生.

Try using a lock() statement around every write to make sure that your writes are not happening simultaneously.

这篇关于WPF(.NET 4.0)内部错误消息:哈希表插入失败.负载系数太高的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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