添加到Hashset< T>中时出现IndexOutOfRangeException

编程入门 行业动态 更新时间:2024-10-11 17:30:58
本文介绍了添加到Hashset< T>中时出现IndexOutOfRangeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个简单的应用程序,它向HashSet <string>中添加了大约700万个短字符串.有时在调用Hashset.Add()时遇到异常:System.Collections.Generic.HashSet`1.IncreaseCapacity():索引超出数组的范围.

I have a simple application that adds about 7 million short strings to a HashSet<string>. Occasionally I get an exception during a call to Hashset.Add(): System.Collections.Generic.HashSet`1.IncreaseCapacity(): Index was outside the bounds of the array.

这是一个间歇性的问题,似乎与内存有关,但这是在具有16 GB的win2k8 R2服务器上,没有太多其他事情了,大部分物理内存都可用.有什么想法吗?

It's an intermittent problem and seems related to memory, but this is on a win2k8 R2 server with 16 GB, not much else going on, most of that physical memory is available. Any ideas?

推荐答案

HashSet<T>不是线程安全的.尤其是在多线程方案中添加项目并且必须增加内部容量时,事情可能会不同步.

The HashSet<T> is not thread-safe. Especially when adding items in a multi-threaded scenario and the internal capacity has to be increased, things can go out of sync.

更多推荐

添加到Hashset&lt; T&gt;中时出现IndexOutOfRangeException

本文发布于:2023-11-03 21:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556128.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中时   amp   Hashset   lt   IndexOutOfRangeException

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!