Skip to content
Peter Csajtai edited this page Nov 9, 2018 · 5 revisions

Ensures that the caller won't have to wait indefinitely for an operation to finish by setting a maximum time range within the given operation should be executed.

Configuration

// 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 cancelled.
        .After(TimeSpan.FromSeconds(15))

        // (optional) Set a callback delegate which will be invoked when the 
        // given operation is timed out
        .OnTimeout((context) => Console.WriteLine("Operation timed out."))));

Available configuration options

  • .After(TimeSpan) - Sets after how much time should be the given operation cancelled.
  • .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 which will be invoked when the given operation is timing out.

When the configured time is expired the framework throws a custom OperationTimeoutException exception.

Clone this wiki locally