


The INotif圜ollectionChanged event defined by this interface is typically raised from a write method but is consumed from the user interface thread. The implementation of INotif圜ollectionChanged gives a typical example of this situation. In some situations, a method with write access needs to allow other threads to read the object before another write is performed on the object.

a delegate call) tries to read or write a field. when a reader method tries to write a field, or when a non-annotated method (e.g. The reader/writer synchronized object will throw a ThreadAccessException whenever some code tries to access a field from a thread that does not own the correct lock, i.e. Note that property getters and setters and event accessors do not need to be annotated. The class contains a public method is missing a ReaderAttribute or WriterAttribute custom attribute, or another attribute derived from AccessLevelAttribute. The class contains a public or internal field. The ReaderWriterSynchronizedAttribute aspect emits build-time errors in the following situations: Rules enforced by the ReaderWriterSynchronized aspect Public void Set(decimal amount, decimal discount)

Why use the reader-writer synchronized pattern? Problems without locksĬonsider the following example of an Order class which stores an amount and a discount: class Order It requires you to annotate all public methods of your synchronized classes with the ReaderAttribute and WriterAttribute custom attributes. The Reader/Writer Synchronized Threading Model is implemented by the ReaderWriterSynchronizedAttribute aspect. The Reader/Writer Synchronized Threading Model uses locks to allow several read-only methods to execute simultaneously on one instance, but guarantee that writer methods have exclusive access. When a class instance is concurrently used by multiple threads, accesses must be synchronized to prevent data races, which typically result in data inconsistencies and corruption of data structures. Reader/Writer Synchronized Threading Model
