[Previous] [Contents] [Next]

Thread Safety and the .NET Classes

One question I see quite often in the newsgroups and mailing lists is whether all the .NET System.* classes are thread-safe. The answer is "No, and they should not be." You could severely cripple a system's performance if all classes serialized access to their functionality. For example, imagine attempting to use one of the collection classes if it obtained a monitor lock each time you called its Add method. Now let's say you instantiate a collection object and add about a thousand objects to it. Performance would be dismal-to the point of making the system unusable.

[Previous] [Contents] [Next]