Multi threading issue in CanReadProperty

Multi threading issue in CanReadProperty

Old forum URL: forums.lhotka.net/forums/t/8456.aspx


Andreas posted on Tuesday, February 02, 2010

Hi,
we ran into a multi threading problem in BusinessBase.CanReadProperty with WPF. Two threads tried to insert the same key into the _readResultCache dictionary. I think the _readResultCache variable needs to be locked (?)

Andreas

Original code of Csla381:

[EditorBrowsable(EditorBrowsableState.Advanced)]
public virtual bool CanReadProperty(string propertyName)
{
bool result = true;
VerifyAuthorizationCache();
if (!_readResultCache.TryGetValue(propertyName, out result))
{
result = true;
if (AuthorizationRules.HasReadAllowedRoles(propertyName))
{
// some users are explicitly granted read access
// in which case all other users are denied
if (!AuthorizationRules.IsReadAllowed(propertyName))
result = false;
}
else if (AuthorizationRules.HasReadDeniedRoles(propertyName))
{
// some users are explicitly denied read access
if (AuthorizationRules.IsReadDenied(propertyName))
result = false;
}
// store value in cache
_readResultCache.Add(propertyName, result);
}

return result;
}

rxelizondo replied on Tuesday, February 02, 2010

I may be wrong about this but I believe that the CSLA is not thread safe by design….. at least not on instance members.

Making it thread safe would probably incur in a big performance hit and not everyone needs thread safe so I believe is up to you to decide to implement thread safety if you really need it.

Andreas replied on Wednesday, February 03, 2010

Youre right. I was not sure about it because some pieces of csla uses the lock key word.

Thanks,
Andreas

Copyright (c) Marimer LLC