小编Cor*_*reM的帖子

循环开始停止时C#做

我试图为这个循环制作一个停止按钮,但它运行无限期,当我点击按钮2时没有任何反应

bool dowhile = false;
private void button1_Click(object sender, EventArgs e)
{
    do
    {
        for (int i = listbox1.Items.Count - 1; i >= 0; i--)
        {
            string textstring = listbox1.Items[i].ToString();
            richTextBox1.AppendText("" + textstring + ": Done\n");
            Thread.Sleep(1000);
        }
    } while (!dowhile);
}
private void button2_Click(object sender, EventArgs e)
{
    this.dowhile = true;
}
Run Code Online (Sandbox Code Playgroud)

我哪里出错了?

sry for"lvlchanger"错字,现在代码还可以,没有什么遗漏

我也在寻找一个不那么长的修复:))

c# loops for-loop while-loop do-while

2
推荐指数
1
解决办法
2605
查看次数

标签 统计

c# ×1

do-while ×1

for-loop ×1

loops ×1

while-loop ×1