Defensive anti-multithreading class implementation
问题 I have an object that is not safe for multithreaded applications (in several ways), and I want to provide an internal check to make sure that critical methods are not accessed concurrently. Question What techniques should I employ to detect and prevent multiple threads from accessing my class? Is it sufficient to track the Thread.ID on all methods, properties, etc. that the consumer may use? 回答1: Just document that it isn't thread safe. That's the convention used by the classes in .NET. 回答2: