C# 如何将流控制返回到for循环?

C# 如何将流控制返回到for循环?,c#,windows-phone-8,for-loop,C#,Windows Phone 8,For Loop,我正在尝试编写一个循环代码,以将代码块重新执行3次。此时,代码启动并执行一次,但不会使用for循环重复 我已经为循环设置了一个断点,它只通过循环一次 private async void startBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e) { int i; int roundMax = 3; for (i = 1; i <= roundM

我正在尝试编写一个循环代码,以将代码块重新执行3次。此时,代码启动并执行一次,但不会使用
for
循环重复

我已经为循环设置了一个断点,它只通过循环一次

    private async void startBtn_Tap(object sender, System.Windows.Input.GestureEventArgs e)
    {
        int i;
        int roundMax = 3;

         for (i = 1; i <= roundMax; i++)
         {
                //delay stop watch start to allow time to get ready.
                TimeSpan time = TimeSpan.FromSeconds(1);
                await System.Threading.Tasks.Task.Delay(time);


                //set text box editing to false to prevent illegal input.
                wrkTbx.IsEnabled = false;
                restTbx.IsEnabled = false;
                roundSlider.IsEnabled = false;
                roundsTbx.IsEnabled = false;

                StopGoCvs.Background = new SolidColorBrush(Colors.Green);
                //startSoundElmt.Play();
                // set up the timer
                myTimer = new DispatcherTimer();
                myTimer.Interval = new TimeSpan(0, 0, 0, 0, 1);

                myTimer.Tick += myTimer_Tick;

                // start both timers
                myTimer.Start();
                myStopwatch.Start();



        }

    }
private async void startBtn_Tap(对象发送方,System.Windows.Input.GestureEventArgs e)
{
int i;
int-roundMax=3;

对于(i=1;i这是一个逻辑问题,我怀疑它会在某个时候退出for循环,假设您正在使用Visual Studio,我会在每个步骤中使用断点并运行程序以查看失败的地方,您可能缺少返回,或者在其他地方

您是否已将startbtnu Tap实现包装在try/catch中,以查看是否有未处理的异常正在发生错误?您能分享您放置断点的确切位置吗?@julealgon,我将断点放置在for循环的同一行上。您发布的代码将执行循环三次。因此,如果您的循环没有执行,那么您发布的代码与实际代码不同。另外,如果您能解释为什么您是一个)想要执行该代码三次,b)为什么你只订阅myTimer.Tick事件在你启动计时器之后,这会很有帮助。从表面上看,整个方法毫无意义。三个1ms计时器,启动同一秒表三次,设置同一背景三次,这很奇怪。@PeterDuniho循环中的代码调用计时器_Tick和in turn调用一个interval timer方法,这就是为什么我怀疑计时器没有循环,因为流的控制仍然在其中一个方法中?a)执行三次的原因是因为它是一个interval timer,所以每次执行都是一轮,即3轮。b)启动计时器后启动计时器是我的错误。我是g现在我想发布我问题中的另外两个链接方法,timer_tick和intervalMethod。