-
Notifications
You must be signed in to change notification settings - Fork 5
Timeout
Peter Csajtai edited this page Jul 9, 2020
·
5 revisions
Ensures that the caller won't have wait indefinitely for an operation to finish by setting a maximum time range within the given operation should be executed.
// Create a new bot policy
var policy = new BotPolicy();
// Or with a return value
var policy = new BotPolicy<HttpResponseMessage>();
// Configure the policy to use timeout on operations
policy.Configure(policyConfig => policyConfig
.Timeout(timeoutConfig => timeoutConfig
// Set after how much time should be the given operation canceled.
.After(TimeSpan.FromSeconds(15))
// (optional) Set a callback delegate to invoke when the
// given operation is timed out
.OnTimeout((context) => Console.WriteLine("Operation timed out."))));
-
.After(TimeSpan)
- Sets after how much time should be the given operation canceled. -
.OnTimeout(Action<ExecutionContext>)
- Sets the delegate which will be invoked when the given operation is timing out. -
.OnTimeoutAsync(Func<ExecutionContext, Task>)
- Sets the asynchronous delegate to invoke when the given operation is timing out.
When the configured time is expired the framework throws a custom
OperationTimeoutException
exception.