Dela via


Implementing a Custom Detection Strategy

Retired Content

This content and the technology described is outdated and is no longer being maintained. For more information, see Transient Fault Handling.

patterns & practices Developer Center

To implement a custom detection strategy for a service you must implement the ITransientErrorDetectionStrategy interface shown below.

public interface ITransientErrorDetectionStrategy
{
    /// <summary>
    /// Determines whether the specified exception represents a transient failure   
    /// that can be compensated by a retry.
    /// </summary>
    /// <param name="ex">The exception object to be verified.</param>
    /// <returns>True if the specified exception is considered as transient, 
    /// otherwise false.</returns>
    bool IsTransient(Exception ex);
}

The IsTransient method returns a Boolean value indicating whether a particular exception thrown by the service should be regarded as transient. If it is transient, the block retries the method that threw the exception based on the current retry strategy.

For an example of a detection strategy implementation, refer to the source code of the four built-in detection strategy classes in the TransientFaultHandling project.

  • StorageTransientErrorDetectionStrategy
  • CacheTransientErrorDetectionStrategy
  • ServiceBusTransientErrorDetectionStrategy
  • SqlAzureTransientErrorDetectionStrategy

Next Topic | Previous Topic | Home

Last built: June 7, 2012