Skip to content

Instantly share code, notes, and snippets.

@hodzanassredin
Created October 24, 2011 19:06
Show Gist options
  • Select an option

  • Save hodzanassredin/1309846 to your computer and use it in GitHub Desktop.

Select an option

Save hodzanassredin/1309846 to your computer and use it in GitHub Desktop.
try-retry in c# fault tolerance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FaultTolerance
{
class Program
{
static void Main(string[] args)
{
var maxAttempts = Int32.Parse(args[0]);
var numberOfVersions = Int32.Parse(args[1]);
var version = 0;
var attempts = 1;
Begin:
try
{
Console.WriteLine("Starting attempt number " + attempts);
version = attempts % numberOfVersions;
SelectAndDoVersion(version);
}
catch (Exception ex)
{
Console.WriteLine("Version " + version + " failed");
if (++attempts > maxAttempts) throw ex;
goto Begin;
}
finally
{
}
}
private static void SelectAndDoVersion(int versionNumber)
{
Console.WriteLine("Trying to do ver " + versionNumber);
throw new NotImplementedException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment