Transient Fauld Handling and simple Process

Topics: Enterprise Library Core
Jul 11, 2012 at 11:37 AM

Hi,

I wanted to use the transient fault application handling and a simple Process launching a exe.

Is it possible ?

Has anyone any example of that ?

 

var process = Process.Start(startOptions);

process.WaitForExit();

 

Thanks!

Jul 12, 2012 at 5:48 AM

I'm not sure I understand what you are trying to accomplish.  Are you trying to use the Transient Fault Handling Block outside of Azure?  If so, then yes you can use it.  You will have to write your own strategies and configure the block using code.

For example, you could create a SQL Deadlock detection strategy and use that:

    public class SqlDeadlockStrategy : ITransientErrorDetectionStrategy
    {
        public bool IsTransient(Exception ex)
        {
            var sqlException = ex as SqlException;
            return sqlException != null && sqlException.Number == 1205;
        }
    }

    var retryStrategy = new Incremental(5, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000));

    var retryPolicy = new RetryPolicy<SqlDeadlockStrategy>(retryStrategy);

    // Receive notifications about retries.
    retryPolicy.Retrying += (sender, arguments) =>
    {
        // Log details of the retry.
        var msg = String.Format("Retry - Count:{0}, Delay:{1}, Exception:{2}",
            arguments.CurrentRetryCount, arguments.Delay, arguments.LastException);

        Trace.WriteLine(msg, "Information");
    };

    try
    {
        // Do some work that may result in a transient fault.
        retryPolicy.ExecuteAction(
            () =>
            {
                DoDatabaseAction();
            });
    }
    catch (Exception)
    {
        throw;
    }

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Jul 12, 2012 at 8:29 AM

Hi,

I modified my program.

Now I have one method that performs an export of an Windows Azure SQL database using SQL Dac Import Export Service.

retryPolicy.ExecuteAction(
                            ()
                            =>
                            {
                                requestKey = ExportDatabase(targetDatabase, targetFile, this.backupFolder);
                            }
                            );
The method has to throw exception on error for the retry process to work, am I correct ?

Thanks for your help.