views:

21

answers:

1

I have the following code:

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

The "ServicesQueueActiveDict is a caprock.dictionary.

I get the error referenced in this subject, "This key is already associated with an element of this collection." when the If branch executes. The problem is, if the nID exists, why is the code then trying to add it again? Shouldn't it then execute the Else branch?

nID is a simple integer, by the way.

+1  A: 

Is there any risk here of threading issues? Your code doesn't show any locking so could another thread be coming through between the execution of the .Exists test and the addition attempt?

Richard J Foster
I'll look into it. I'm not sure, at the moment. In fact, how would I know that exactly?
crackedcornjimmy
If it is a threading issue it could be difficult to track down. I usually resort to some form of logging, typically using the log4net framework as it handles messages from multiple threads quite nicely.
Richard J Foster