Threading cookbook - Afr0Games/Project-Dollhouse GitHub Wiki
This page contains all the combined knowledge of threading shared by the developers for the developers. If you can, please contribute, but only if you know what you're saying/writing.
Callbacks
Never lock around code that can/will result in a callback, as it is not guaranteed to release the lock. Any such code is a deadlock waiting to happen.
Enumeration
When enumerating a collection that you suspect (or better yet, know) will be used by more than one thread, always lock it. Enumerating a collection is inherently not thread-safe. If all else fails, you can always make a copy of the collection before enumeration, but this is not recommended unless you know that the collection doesn't need to be fresh (really, this is impossible to know, so only use this technique with collections you know won't update frequently or won't affect other code if an out of date representation of the collection is passed down the proverbial chain.)