PostSharpAPI ReferencePost­Sharp.​Patterns.​CachingCaching­ServicesSuspend­Dependency­Propagation
Open sandboxFocus

CachingServices.SuspendDependencyPropagation Method


Temporarily suspends propagation of dependencies from subsequently called methods to the caller method.

public static IDisposable SuspendDependencyPropagation()
Type Description

IDisposable representation of the suspension. Disposing this object resumes the normal dependency propagation.


By default, calling a cached method while another PostSharp.Patterns.Caching.CachingContext is active automatically adds the former as a dependency of the later. Since the CurrentContext is stored in an AsyncLocal<T> variable, it may be inadvertently used after the method call associated with it had already ended. This can happen, for example, when method calls Run(Action) and does not depend on the resulting Task.

This context leak does not break correctness but may lead to unnecessary dependency invalidations. Therefore it is recommended to use this method when calling asynchronous code in the context of cached methods and not being dependent on its result.