我有以下代码:
If Not Application("ServicesQueueActiveDict").Exists( nID ) Then 'we are good to process, this item is not Active....add it now Application("ServicesQueueActiveDict").Add nID, Now Else 'do whatever
“ServicesQueueActiveDict是一个caprock.dictionary。
当If分支执行时,我得到这个主题中引用的错误,“这个键已经与这个集合的一个元素相关联”。问题是,如果nID存在,为什么代码会再次尝试添加它?那么它不应该执行Else分支吗?
顺便说一下,nID是一个简单的整数。
这里有线程问题的风险吗?您的代码没有显示任何锁定,因此在执行.Exists测试和添加尝试之间是否会有另一个线程经过?