I have a method that calls a SQLServer function to perform a free text search against a table. That function will occasionally on the first call result in a SQLException: "Word breaking timed out for the full-text query string". So typically I want to retry that request because it will succeed on subsequent requests. What is good style for structuring the retry logic. At the moment I have the following:
var retryCount = 0;
var results = new List<UserSummaryDto>();
using (var ctx = new UsersDataContext(ConfigurationManager.ConnectionStrings[CONNECTION_STRING_KEY].ConnectionString))
{
for (; ; )
{
try
{
results = ctx.SearchPhoneList(value, maxRows)
.Select(user => user.ToDto())
.ToList();
break;
}
catch (SqlException)
{
retryCount++;
if (retryCount > MAX_RETRY) throw;
}
}
}
return results;
On Error Resume Nextin Visual Basic was conceptually simple - that didn't make it a good idea.varremark. IMO, the compiler should disallow its use where it conceals the object type, as it does here.varcomments. There isn't anything in the above code that conceals the object type.retryCountis clearlyint,resultsis a genericList,ctxis a data context. I did recently have a situation where a variable was initialised by a method where the returned object was not obvious e.g.var someVar = MyInitialiser();. Under those circumstances avardeclaration conceals the type of the variable and should be declared explicitly.