1 回答

TA貢獻1853條經(jīng)驗 獲得超9個贊
您可以通過使用泛型委托來實現(xiàn)此目的:
private async Task<T> Retry<T>(Func<Task<T>> func)
{
try
{
return await func();
}
catch (BillComInvalidSessionException)
{
SessionId = new Lazy<string>(() => LoginAsync().Result);
return await Retry(func);
}
}
然后,您的重試方法將轉(zhuǎn)到:
private async Task<T> ReadWithRetry<T>(string id, string endpoint)
{
return await Retry(async () => await Read<T>(id, endpoint));
}
private async Task<List<T>> ListWithRetry<T>(int start, int count, string endpoint, List<FilterData> filterData = null)
{
return await Retry(async () => await List<T>(start, count, endpoint, filterData));
}
- 1 回答
- 0 關(guān)注
- 105 瀏覽
添加回答
舉報