【发布时间】:2015-08-21 07:41:10
【问题描述】:
即使我在添加之前检查地图是否已经包含密钥,我也会收到此错误..
if (ShortBuffer.ContainsKey(GetTuple(data))) return;
ShortBuffer.Add(GetTuple(data), <----- ERROR OCCURS HERE
new Tuple<Timer, int, bool, Data>(
new Timer(Convert.ToInt32(Ini.ReadValue("intervals", "clientbuffershort"))), 0, false, data));
GetTuple 方法:
private static Tuple<string, string, string> GetTuple(Data data)
{
return new Tuple<string, string, string>(data.AucxisErrorId, data.ClientId, data.Area);
}
有什么想法吗?谢谢!
【问题讨论】:
-
你的应用是多线程的吗...
-
不,不是,这就是我不明白的原因
-
那么我们需要代码来重现问题,以便回答您的问题。 (简短但完整的代码示例)
-
您尝试使用ConcurrentDictionary 以确保它不是线程问题。
-
这对您的问题并不重要,但您应该考虑将其取出
GetTuple(data)并调用一次。我无法重现您的问题是单线程应用程序。一定有什么古怪的事情发生了。你的Data结构是不可变的吗?是不是它在调用之间发生了变化(因为对属性的调用有副作用)?