views:

37

answers:

2
else if (!registryData.ContainsKey(keyName))
{
    keyInvolved = new RegistryKy(keyName);
    lock (registryDataLock)
    {
        registryData.Add(keyName, keyInvolved);
    }
    processInvolved = new Proces(procInvolved);
    keyInvolved.addProcessToDict(processInvolved);
}

keyName is a String which represents a registry key. keyInvolved is the actual registry key object.

I'm being told that im adding a key which already exists, yet i have already checked to see whether it is in there or not???

A: 

This is a stab in the dark, but the fact that you've got a lock on registryDataLock says to me that this is multi-threaded. Is it possible that another thread is adding the key to the dictionary after the call to ContainsKey but before the call to Add?

Also, the similarly-named variables make this code rather hard to read...

Dean Harding
A: 

This should be like this:

else if (!registryData.ContainsKey(kyInvolved))
{
    //keyInvolved = new RegistryKy(kyInvolved);
    lock (registryDataLock)
    {
        //registryData.Add(kyInvolved, keyInvolved);
        registryData.Add(kyInvolved, new RegistryKy(kyInvolved));
    }
    processInvolved = new Proces(procInvolved);
    keyInvolved.addProcessToDict(processInvolved);
}
VoodooChild