我编写了一个通过 API 连接到 Salesforce.com 并查询和更新数据的应用程序。有时,如下所示的方法将无法连接并导致整个应用程序停止运行:
Exception in getMoreResults():
System.Net.WebException: The underlying connection was closed: The connection was closed unexpectedly.
qr = sfservice.queryMore(qr.Locator)
在失败时重试执行的最佳方法是什么?理想情况下,我想在记录失败并停止程序执行之前尝试 3 次。下面是一些伪代码,虽然我不确定它的可行性。任何帮助深表感谢!
public QueryResult getMoreResults(QueryResult qr)
{
try
{
qr = sfservice.queryMore(qr.queryLocator);
}
catch (WebException ex)
{
bool success = false;
//Todo retry this query until it is either successful or has failed three times
for (int i = 0; i <= 3; i++)
{
//somehow set success boolean here
if(success == false)
{
qr = sfservice.queryMore(qr.queryLocator);
//log error and error attempt
}
else
{
//exit this method and return to normal flow?
}
}
}
catch(Exception ex)
{
//log the error
AppSettings.log.Error(ex.Message.ToString());
}
return qr;
}