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
[Metric("UsedFeatures", "PostSharp.Patterns.Threading.Actor")]
public sealed class ActorAttribute : ThreadAwareAttribute, ITypeLevelAspect, ITypeLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, ICloneAwareAspect, IInstanceScopedAspect, IAspectProvider, IService, IAdviceProvider, IAspect, IThreadAwareImplementationProvider, IQueryInterface, IActor, IDispatcherObject, IThreadAware

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.


Name Description


Name Description

Explicit Interface Implementations

Name Description

Gets the IActorDispatcher for the current actor.


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