Class Policy<TResult>
- Namespace
- Polly
- Assembly
- Polly.dll
Transient fault handling policies that can be applied to delegates returning results of type TResult
public abstract class Policy<TResult> : IAsyncPolicy<TResult>, ISyncPolicy<TResult>, IsPolicy
Type Parameters
TResult
- Inheritance
-
Policy<TResult>
- Implements
-
IAsyncPolicy<TResult>ISyncPolicy<TResult>
- Derived
-
PolicyWrap<TResult>
- Inherited Members
Properties
PolicyKey
A key intended to be unique to each Policy instance, which is passed with executions as the Context.PolicyKey property.
public string PolicyKey { get; }
Property Value
Methods
Execute(Func<Context, CancellationToken, TResult>, Context, CancellationToken)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
Parameters
action
Func<Context, CancellationToken, TResult>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TResult
The value returned by the action
Execute(Func<Context, CancellationToken, TResult>, IDictionary<string, object>, CancellationToken)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<Context, CancellationToken, TResult> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)
Parameters
action
Func<Context, CancellationToken, TResult>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TResult
The value returned by the action
Exceptions
- ArgumentNullException
contextData
Execute(Func<Context, TResult>, Context)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<Context, TResult> action, Context context)
Parameters
action
Func<Context, TResult>The action to perform.
context
ContextContext data that is passed to the exception policy.
Returns
- TResult
The value returned by the action
Exceptions
- ArgumentNullException
context
- ArgumentNullException
contextData
Execute(Func<Context, TResult>, IDictionary<string, object>)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<Context, TResult> action, IDictionary<string, object> contextData)
Parameters
action
Func<Context, TResult>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
Returns
- TResult
The value returned by the action
Exceptions
- ArgumentNullException
contextData
- ArgumentNullException
contextData
Execute(Func<CancellationToken, TResult>, Context, CancellationToken)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, TResult>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TResult
The value returned by the action
Execute(Func<CancellationToken, TResult>, IDictionary<string, object>, CancellationToken)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<CancellationToken, TResult> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, TResult>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TResult
The value returned by the action
Exceptions
- ArgumentNullException
contextData
Execute(Func<CancellationToken, TResult>, CancellationToken)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<CancellationToken, TResult> action, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, TResult>The action to perform.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- TResult
The value returned by the action
Execute(Func<TResult>)
Executes the specified action within the policy and returns the Result.
public TResult Execute(Func<TResult> action)
Parameters
action
Func<TResult>The action to perform.
Returns
- TResult
The value returned by the action
Execute(Func<TResult>, Context)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<TResult> action, Context context)
Parameters
action
Func<TResult>The action to perform.
context
ContextContext data that is passed to the exception policy.
Returns
- TResult
The value returned by the action
Exceptions
- ArgumentNullException
context
- ArgumentNullException
contextData
Execute(Func<TResult>, IDictionary<string, object>)
Executes the specified action within the policy and returns the result.
public TResult Execute(Func<TResult> action, IDictionary<string, object> contextData)
Parameters
action
Func<TResult>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
Returns
- TResult
The value returned by the action
Exceptions
- ArgumentNullException
contextData
- ArgumentNullException
contextData
ExecuteAndCapture(Func<Context, CancellationToken, TResult>, Context, CancellationToken)
Executes the specified action within the policy and returns the captured result.
public PolicyResult<TResult> ExecuteAndCapture(Func<Context, CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
Parameters
action
Func<Context, CancellationToken, TResult>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- PolicyResult<TResult>
The captured result
ExecuteAndCapture(Func<Context, CancellationToken, TResult>, IDictionary<string, object>, CancellationToken)
Executes the specified action within the policy and returns the captured result.
public PolicyResult<TResult> ExecuteAndCapture(Func<Context, CancellationToken, TResult> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)
Parameters
action
Func<Context, CancellationToken, TResult>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- PolicyResult<TResult>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCapture(Func<Context, TResult>, Context)
Executes the specified action within the policy and returns the captured result.
public PolicyResult<TResult> ExecuteAndCapture(Func<Context, TResult> action, Context context)
Parameters
action
Func<Context, TResult>The action to perform.
context
ContextContext data that is passed to the exception policy.
Returns
- PolicyResult<TResult>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCapture(Func<Context, TResult>, IDictionary<string, object>)
Executes the specified action within the policy and returns the captured result.
public PolicyResult<TResult> ExecuteAndCapture(Func<Context, TResult> action, IDictionary<string, object> contextData)
Parameters
action
Func<Context, TResult>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
Returns
- PolicyResult<TResult>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCapture(Func<CancellationToken, TResult>, Context, CancellationToken)
Executes the specified action within the policy and returns the captured result.
public PolicyResult<TResult> ExecuteAndCapture(Func<CancellationToken, TResult> action, Context context, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, TResult>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- PolicyResult<TResult>
The captured result
ExecuteAndCapture(Func<CancellationToken, TResult>, IDictionary<string, object>, CancellationToken)
Executes the specified action within the policy and returns the captured result.
public PolicyResult<TResult> ExecuteAndCapture(Func<CancellationToken, TResult> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, TResult>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- PolicyResult<TResult>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCapture(Func<CancellationToken, TResult>, CancellationToken)
Executes the specified action within the policy and returns the captured result
public PolicyResult<TResult> ExecuteAndCapture(Func<CancellationToken, TResult> action, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, TResult>The action to perform.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- PolicyResult<TResult>
The captured result
ExecuteAndCapture(Func<TResult>)
Executes the specified action within the policy and returns the captured result
public PolicyResult<TResult> ExecuteAndCapture(Func<TResult> action)
Parameters
action
Func<TResult>The action to perform.
Returns
- PolicyResult<TResult>
The captured result
ExecuteAndCapture(Func<TResult>, Context)
Executes the specified action within the policy and returns the captured result.
public PolicyResult<TResult> ExecuteAndCapture(Func<TResult> action, Context context)
Parameters
action
Func<TResult>The action to perform.
context
ContextContext data that is passed to the exception policy.
Returns
- PolicyResult<TResult>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCapture(Func<TResult>, IDictionary<string, object>)
Executes the specified action within the policy and returns the captured result.
public PolicyResult<TResult> ExecuteAndCapture(Func<TResult> action, IDictionary<string, object> contextData)
Parameters
action
Func<TResult>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
Returns
- PolicyResult<TResult>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken)
Parameters
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- InvalidOperationException
Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.
ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)
Parameters
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCaptureAsync(Func<Context, Task<TResult>>, Context)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, Task<TResult>> action, Context context)
Parameters
action
Func<Context, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<Context, Task<TResult>>, Context, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, Task<TResult>> action, Context context, bool continueOnCapturedContext)
Parameters
action
Func<Context, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<Context, Task<TResult>>, IDictionary<string, object>)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, Task<TResult>> action, IDictionary<string, object> contextData)
Parameters
action
Func<Context, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCaptureAsync(Func<Context, Task<TResult>>, IDictionary<string, object>, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Context, Task<TResult>> action, IDictionary<string, object> contextData, bool continueOnCapturedContext)
Parameters
action
Func<Context, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>>, Context, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>>, Context, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- InvalidOperationException
Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.
ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>>, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>>, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- InvalidOperationException
Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.
ExecuteAndCaptureAsync(Func<Task<TResult>>)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Task<TResult>> action)
Parameters
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<Task<TResult>>, Context)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Task<TResult>> action, Context context)
Parameters
action
Func<Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<Task<TResult>>, Context, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Task<TResult>> action, Context context, bool continueOnCapturedContext)
Parameters
action
Func<Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<Task<TResult>>, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Task<TResult>> action, bool continueOnCapturedContext)
Parameters
action
Func<Task<TResult>>The action to perform.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
ExecuteAndCaptureAsync(Func<Task<TResult>>, IDictionary<string, object>)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Task<TResult>> action, IDictionary<string, object> contextData)
Parameters
action
Func<Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAndCaptureAsync(Func<Task<TResult>>, IDictionary<string, object>, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<PolicyResult<TResult>> ExecuteAndCaptureAsync(Func<Task<TResult>> action, IDictionary<string, object> contextData, bool continueOnCapturedContext)
Parameters
action
Func<Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<PolicyResult<TResult>>
The captured result
Exceptions
- ArgumentNullException
contextData
ExecuteAsync(Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken)
Parameters
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Context, CancellationToken, Task<TResult>>, Context, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
Exceptions
- InvalidOperationException
Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.
ExecuteAsync(Func<Context, CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)
Parameters
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Context, CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Context, CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<Context, CancellationToken, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
Exceptions
- ArgumentNullException
contextData
ExecuteAsync(Func<Context, Task<TResult>>, Context)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Context, Task<TResult>> action, Context context)
Parameters
action
Func<Context, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Context, Task<TResult>>, Context, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Context, Task<TResult>> action, Context context, bool continueOnCapturedContext)
Parameters
action
Func<Context, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Context, Task<TResult>>, IDictionary<string, object>)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Context, Task<TResult>> action, IDictionary<string, object> contextData)
Parameters
action
Func<Context, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Context, Task<TResult>>, IDictionary<string, object>, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Context, Task<TResult>> action, IDictionary<string, object> contextData, bool continueOnCapturedContext)
Parameters
action
Func<Context, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<CancellationToken, Task<TResult>>, Context, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<CancellationToken, Task<TResult>>, Context, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<CancellationToken, Task<TResult>> action, Context context, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
Exceptions
- InvalidOperationException
Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.
ExecuteAsync(Func<CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<CancellationToken, Task<TResult>>, IDictionary<string, object>, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<CancellationToken, Task<TResult>> action, IDictionary<string, object> contextData, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
Exceptions
- ArgumentNullException
contextData
ExecuteAsync(Func<CancellationToken, Task<TResult>>, CancellationToken)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<CancellationToken, Task<TResult>>, CancellationToken, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<CancellationToken, Task<TResult>> action, CancellationToken cancellationToken, bool continueOnCapturedContext)
Parameters
action
Func<CancellationToken, Task<TResult>>The action to perform.
cancellationToken
CancellationTokenA cancellation token which can be used to cancel the action. When a retry policy is in use, also cancels any further retries.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
Exceptions
- InvalidOperationException
Please use asynchronous-defined policies when calling asynchronous ExecuteAsync (and similar) methods.
ExecuteAsync(Func<Task<TResult>>)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Task<TResult>> action)
Parameters
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Task<TResult>>, Context)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Task<TResult>> action, Context context)
Parameters
action
Func<Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Task<TResult>>, Context, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Task<TResult>> action, Context context, bool continueOnCapturedContext)
Parameters
action
Func<Task<TResult>>The action to perform.
context
ContextContext data that is passed to the exception policy.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Task<TResult>>, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Task<TResult>> action, bool continueOnCapturedContext)
Parameters
action
Func<Task<TResult>>The action to perform.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Task<TResult>>, IDictionary<string, object>)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Task<TResult>> action, IDictionary<string, object> contextData)
Parameters
action
Func<Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
Returns
- Task<TResult>
The value returned by the action
ExecuteAsync(Func<Task<TResult>>, IDictionary<string, object>, bool)
Executes the specified asynchronous action within the policy and returns the result.
public Task<TResult> ExecuteAsync(Func<Task<TResult>> action, IDictionary<string, object> contextData, bool continueOnCapturedContext)
Parameters
action
Func<Task<TResult>>The action to perform.
contextData
IDictionary<string, object>Arbitrary data that is passed to the exception policy.
continueOnCapturedContext
boolWhether to continue on a captured synchronization context.
Returns
- Task<TResult>
The value returned by the action
HandleResult(Func<TResult, bool>)
Specifies a filter on the return result values that this strongly-typed generic policy will handle.
public static PolicyBuilder<TResult> HandleResult(Func<TResult, bool> resultPredicate)
Parameters
Returns
- PolicyBuilder<TResult>
The PolicyBuilder instance.
HandleResult(TResult)
Specifies a return result value which the strongly-typed generic policy will handle.
public static PolicyBuilder<TResult> HandleResult(TResult result)
Parameters
result
TResultThe TResult value this policy will handle.
Returns
- PolicyBuilder<TResult>
The PolicyBuilder instance.
Remarks
This policy filter matches the result
value returned using .Equals(), ideally suited for value types such as int and enum. To match characteristics of class return types, consider the overload taking a result predicate.
Handle<TException>()
Specifies the type of exception that this policy can handle.
public static PolicyBuilder<TResult> Handle<TException>() where TException : Exception
Returns
- PolicyBuilder<TResult>
The PolicyBuilder instance.
Type Parameters
TException
The type of the exception to handle.
Handle<TException>(Func<TException, bool>)
Specifies the type of exception that this policy can handle with additional filters on this exception type.
public static PolicyBuilder<TResult> Handle<TException>(Func<TException, bool> exceptionPredicate) where TException : Exception
Parameters
exceptionPredicate
Func<TException, bool>The exception predicate to filter the type of exception this policy can handle.
Returns
- PolicyBuilder<TResult>
The PolicyBuilder instance.
Type Parameters
TException
The type of the exception.
WithPolicyKey(string)
Sets the PolicyKey for this Policy instance.
public Policy<TResult> WithPolicyKey(string policyKey)
Parameters
Returns
- Policy<TResult>
Wrap(Policy)
Wraps the specified inner policy.
public PolicyWrap<TResult> Wrap(Policy innerPolicy)
Parameters
innerPolicy
PolicyThe inner policy.
Returns
- PolicyWrap<TResult>
PolicyWrap.PolicyWrap.
Wrap(Policy<TResult>)
Wraps the specified inner policy.
public PolicyWrap<TResult> Wrap(Policy<TResult> innerPolicy)
Parameters
innerPolicy
Policy<TResult>The inner policy.
Returns
- PolicyWrap<TResult>
PolicyWrap.PolicyWrap.
WrapAsync(Policy)
Wraps the specified inner policy.
public PolicyWrap<TResult> WrapAsync(Policy innerPolicy)
Parameters
innerPolicy
PolicyThe inner policy.
Returns
- PolicyWrap<TResult>
PolicyWrap.PolicyWrap.
WrapAsync(Policy<TResult>)
Wraps the specified inner policy.
public PolicyWrap<TResult> WrapAsync(Policy<TResult> innerPolicy)
Parameters
innerPolicy
Policy<TResult>The inner policy.
Returns
- PolicyWrap<TResult>
PolicyWrap.PolicyWrap.