SuspendDependencyPropagation()
Temporarily suspends propagation of dependencies from subsequently called methods to the caller method.
Declaration
public static IDisposable SuspendDependencyPropagation()Returns
| Type | Description |
|---|---|
| IDisposable | An IDisposable that represents the suspension. Disposing this object resumes the normal dependency propagation. |
Remarks
By default, calling a cached method while another PostSharp.Patterns.Caching.CachingContext is active automatically adds the former as a dependency of the latter. 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 a 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.