Created
January 15, 2013 15:33
-
-
Save i-e-b/4539479 to your computer and use it in GitHub Desktop.
Sql deadlock handler
This file contains 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
public class With | |
{ | |
const int SqlDeadlockErrorNumber = 1205; | |
const int RetryLimit = 10; | |
public static T DeadlockRetry<T>(Func<T> thingToTry) | |
{ | |
var lastError = new Exception("Unknown state"); | |
for (int i = 0; i < RetryLimit; i++) | |
{ | |
try | |
{ | |
return thingToTry(); | |
} | |
catch (SqlException error) | |
{ | |
if (error.Number != SqlDeadlockErrorNumber) throw; | |
lastError = error; | |
} | |
} | |
throw lastError; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment