Created
October 24, 2011 19:06
-
-
Save hodzanassredin/1309846 to your computer and use it in GitHub Desktop.
try-retry in c# fault tolerance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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