PostSharpAPI ReferencePost­Sharp.​Patterns.​ThreadingActor­Attribute
Open sandboxFocus

ActorAttribute Class

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.

Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
[ProvideAspectRole("ThreadingModel")]
[AspectRoleDependency]
[AspectRoleDependency]
[AspectRoleDependency]
[AspectRoleDependency]
[Metric("UsedFeatures", "PostSharp.Patterns.Threading.Actor")]
[IntroduceInterface]
[HasConstraint]
[Serializer]
public sealed class ActorAttribute : ThreadAwareAttribute, ITypeLevelAspect, ITypeLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, ICloneAwareAspect, IInstanceScopedAspect, IAspectProvider, IService, IAdviceProvider, IAspect, IThreadAwareImplementationProvider, 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
OnEventInvoke(EventInterceptionArgs)
OnInstanceConstructed()
ProvideAspects(Type)

Explicit Interface Implementations

Name Description
IActor.Dispatcher

Gets the IActorDispatcher for the current actor.

IDispatcherObject.Dispatcher

Gets the IDispatcher that controls access to methods of the current object.