PostSharp//API Reference/Post­Sharp.​Patterns.​Threading/Background­Attribute
Open sandboxFocus

Class BackgroundAttribute

Custom attribute that, when applied on a method, causes the method to execute in the background. This aspect can be applied to a method with void or Task return type.

Namespace: PostSharp.Patterns.Threading
Assembly: PostSharp.Patterns.Threading.dll
Syntax
[MethodInterceptionAspectConfiguration(SerializerType = null)]
[ProvideAspectRole("Threading")]
[AspectRoleDependency]
[AspectRoleDependency]
[AspectRoleDependency]
[AspectTypeDependency]
[Metric("UsedFeatures", "PostSharp.Patterns.Threading.BackgroundMethod")]
[LinesOfCodeAvoided(1)]
[AspectDescription("Executes the method asynchronously in the thread pool")]
public sealed class BackgroundAttribute : MethodInterceptionAspect, IMethodLevelAspectBuildSemantics, IAspectBuildSemantics, IValidableAnnotation, IAsyncMethodInterceptionAspect, IMethodInterceptionAspect, IMethodLevelAspect, IAspect

Constructors

Name Description
BackgroundAttribute()

Initializes a new BackgroundAttribute.

Properties

Name Description
IsLongRunning

Specifies that the method is long-running and should be executed on its own thread, if that is supported on the target platform. If false, the method will be executed in the thread pool.

Methods

Name Description
CompileTimeValidate(MethodBase)

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

OnInvoke(MethodInterceptionArgs)

Method invoked instead of the method to which the aspect has been applied.

OnInvokeAsync(MethodInterceptionArgs)

Method invoked instead of the method to which the aspect has been applied.