Open sandboxFocus

Class DispatchedAttribute

Custom attribute that, when applied on a method, specifies that the method should be executed in UI thread.

Inheritance
DispatchedAttribute
Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method|AttributeTargets.Interface)]
[ProvideAspectRole("Threading")]
[MulticastAttributeUsage(MulticastTargets.Method, TargetExternalMemberAttributes = MulticastAttributes.Internal, AllowMultiple = false)]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, "Tracing")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, "Caching")]
[AspectRoleDependency(AspectDependencyAction.Order, AspectDependencyPosition.Before, "CacheInvalidation")]
[Metric("UsedFeatures", "PostSharp.Patterns.Threading.DispatchedMethod")]
[LinesOfCodeAvoided(0)]
[Serializer(typeof(DispatchedAttribute.Serializer))]
public sealed class DispatchedAttribute : MethodLevelAspect, IMethodLevelAspect, IMethodLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, IAspectProvider, IAspect, IService
Remarks

Execution of the method can be synchronous or asynchronous according to the value of the FireAndForget property.

This aspect can be applied to instance methods of UI controls (WinForms or WPF), or to any class implementing the IDispatcherObject manually.

Constructors

Name Description
DispatchedAttribute()

Initializes a new DispatchedAttribute in blocking mode.

DispatchedAttribute(DispatchedExecutionMode)

Initializes a new DispatchedAttribute and specifies whether the execution mode should be blocking or non-blocking.

DispatchedAttribute(PortableFormatterConstructorContext)
DispatchedAttribute(bool)

Initializes a new DispatchedAttribute.

Properties

Name Description
ExecutionMode

When the aspect is applied to a void non-async method, this property determines whether the caller will continue immediately after enqueuing the call to the target method, without waiting for the method to complete. The default value is Blocking.

FireAndForget

When the aspect is applied to a void non-async method, this property determines whether the caller will continue immediately after enqueuing the call to the target method, without waiting for the method to complete. The default value is false.

Methods

Name Description
CompileTimeValidate(MethodBase)

Method invoked at build time to ensure that the aspect has been applied to the right target.