我试图为这个循环制作一个停止按钮,但它运行无限期,当我点击按钮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"错字,现在代码还可以,没有什么遗漏
我也在寻找一个不那么长的修复:))