Custom attribute that, when applied to a class, implements the ActorThreadingModel to this class, in which calls to methods are processed asynchronously from a single thread, suppressing concurrency inside each instance of the target class.
Inheritance
Implements
Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
[ProvideAspectRole("ThreadingModel")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, "Tracing")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, "Caching")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, "CacheInvalidation")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.After, "Validation")]
[Metric("UsedFeatures", "PostSharp.Patterns.Threading.Actor")]
[IntroduceInterface(typeof(IActor), AncestorOverrideAction = InterfaceOverrideAction.Ignore, OverrideAction = InterfaceOverrideAction.Ignore)]
[Serializer(typeof(ActorAttribute.Serializer))]
public sealed class ActorAttribute : ThreadAwareAttribute, ITypeLevelAspect, ITypeLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, ICloneAwareAspect, IInstanceScopedAspect, IAspectProvider, IService, IAdviceProvider, IAspect, IQueryInterface, IActor, IDispatcherObject, IThreadAware
Remarks
Calls to public methods of actors are packaged into messages and appended to a message queue. This message queue is processed by a single thread. Therefore, there is never more than one thread accessing the object, which makes the this object thread safe.
Public methods cannot have out
or ref
parameters. All method invocations are appended to the message queue. In case the method has a return value and is
not async
, the calling thread will wait synchronously for the method to be executed by the actor. Add the
ExplicitlySynchronizedAttribute custom attribute to a method to prevent its execution to be dispatched to the actor queue. Note that using ExplicitlySynchronizedAttribute
breaks the thread-safety guarantees of the ActorThreadingModel.
Several actors can share the same message queue by sharing the same instance of IActorDispatcher interface, which the target class can provide by overriding the IDispatcherObject interface.
Constructors
Name | Description |
---|---|
ActorAttribute() | |
ActorAttribute(PortableFormatterConstructorContext) |
Methods
Name | Description |
---|---|
OnInstanceConstructed() | |
ProvideAspects(Type) |