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 Next
in Visual Basic was conceptually simple - that didn't make it a good idea. – MusiGenesis Jan 28 '11 at 0:12var
remark. IMO, the compiler should disallow its use where it conceals the object type, as it does here. – MusiGenesis Jan 28 '11 at 0:14var
comments. There isn't anything in the above code that conceals the object type.retryCount
is clearlyint
,results
is a genericList
,ctx
is 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 avar
declaration conceals the type of the variable and should be declared explicitly. – David Clarke May 6 '15 at 20:51