Open sandboxFocus

Class ExplicitlySynchronizedAttribute

Custom attribute that, when applied to a method or field, specifies that threading model aspects (derived from ThreadAwareAttribute) should ignore all verifications for this field or method.

Inheritance
ExplicitlySynchronizedAttribute
Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
[AttributeUsage(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field)]
[MulticastAttributeUsage(MulticastTargets.Class|MulticastTargets.Field|MulticastTargets.Method|MulticastTargets.Property, AllowMultiple = false)]
public sealed class ExplicitlySynchronizedAttribute : MulticastAttribute
Remarks

When the custom attribute is applied to a field, accesses to this field are never checked.

When the custom attribute is applied to a method, checking of accesses to all fields is disabled during the whole method execution, for the current thread.

Use this custom attribute when you synchronize accesses to the field or method with another mechanism. It increases the risk that multithreading defects remain undetected, so cover code that uses it with reviews and tests.

Constructors

Name Description
ExplicitlySynchronizedAttribute()

Initializes a new instance of the ExplicitlySynchronizedAttribute class.

ExplicitlySynchronizedAttribute(bool)

Initializes a new instance of the ExplicitlySynchronizedAttribute class and specifies the synchronization strategy.

Properties

Name Description
AppliesToMethodOnly

Gets a value that determines the synchronization strategy. When AppliesToMethodOnly is true, no synchronization code is added to the target method. When it is false, synchronization code is added to allow the method to access other fields or methods of the target object. The default value is false.

See Also