Why is ConcurrentBag so slow in .Net (4.0)? Am I doing it wrong?

Let me ask you this: how realistic is it that you’d have an application which is constantly adding to a collection and never reading from it? What’s the use of such a collection? (This is not a purely rhetorical question. I could imagine there being uses where, e.g., you only read from the collection on … Read more

What is the difference between SynchronizedCollection and the other concurrent collections?

The SynchronizedCollection<T> class was introduced first in .NET 2.0 to provide a thread-safe collection class. It does this via locking so that you essentially have a List<T> where every access is wrapped in a lock statement. The System.Collections.Concurrent namespace is much newer. It wasn’t introduced until .NET 4.0 and it includes a substantially improved and … Read more

What to add for the update portion in ConcurrentDictionary AddOrUpdate

You need to pass a Func which returns the value to be stored in the dictionary in case of an update. I guess in your case (since you don’t distinguish between add and update) this would be: var sessionId = a.Session.SessionID.ToString(); userDic.AddOrUpdate( authUser.UserId, sessionId, (key, oldValue) => sessionId); I.e. the Func always returns the sessionId, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)