【发布时间】:2017-09-02 03:08:24
【问题描述】:
public class PollyTest
{
public void RunWithPolly()
{
Console.WriteLine("RunWithPolly invoked...");
int zero = 0;
int result= 10 / zero;
}
}
在我的主要功能中,我创建了一个策略,如下所示:
var retryPolicy = Policy.Handle<DivideByZeroException>().Retry(3);
PollyTest pollyTest = new PollyTest();
retryPolicy.Execute(() => pollyTest.RunWithPolly());
当我执行此操作时,它总是在第一次运行时失败,并在函数“RunWithPolly”中出现未处理的异常错误。
【问题讨论】:
-
用 DebuggerStepThrough 属性注释方法 RunWithPolly 解决了这个问题。谁能帮我理解为什么会这样?
-
已回答问题,但出于兴趣:您使用的是哪个版本的 VStudio?
标签: polly