我有一个字符串列表,每分钟通过一次 API 调用填充一次,
List<string> lst = new List<string>();
现在我需要在 1 分钟后重试 PerformSomeAction
方法中的代码,如果我的 lst
计数为零,该怎么做?
我可以使用 Polly
吗?
class Program
{
static void Main(string[] args)
{
List<string> lst = new List<string>();
if(lst.Count > 0)
{
//retry after one minute of lst.Count == 0
PerformSomeAction();
}
}
private static void PerformSomeAction()
{
Console.WriteLine("execute");
}
}
最佳答案
这很容易实现:
while(lst.Count == 0)
{
Thread.Sleep(1000*60);
PerformAction();
}
关于c# - 如果某些数据计数为零,如何重试执行一段代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56270034/