我有一个对象,它是不安全的多线程应用程序(在几个方面),我想提供内部检查,以确保关键的方法,不能同时访问。
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.
问题
我应该采用什么技术来检测和访问我的课prevent多线程?
What techniques should I employ to detect and prevent multiple threads from accessing my class?
是否足以跟踪Thread.ID上的所有方法,属性等,消费者可以使用?
Is it sufficient to track the Thread.ID on all methods, properties, etc. that the consumer may use?
只是记录,它不是线程安全的。这是在.NET中使用的类的约定。
Just document that it isn't thread safe. That's the convention used by the classes in .NET.