0

so my question to You is how to make loop when checkbox is checked I tried this code

 private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        Globals.guildId = teamId.Text;
        Globals.time = timeAttack.Text;


        if (attackCheckBox.Checked)
        {
            Attack.PostRequestAttack("https://" + Globals.server + ".herozerogame.com/request.php");

            Testowanie.Text = Testowanie.Text + Globals.attackOutput;

            Thread.Sleep(Globals.delay);
        }



    }

But first it doesn't loop and thread.sleep pauses whole program not only the if part.

  • We have hundreds, if not thousands, of questions with answers on the site explaining that if you block the UI thread, the program will not respond to user input nor redraw the window. See duplicates. See also `async` and `await Task.Delay()` as an alternative to `Thread.Sleep()` that would allow the code you posted to work fine without moving everything to a different thread. – Peter Duniho Jan 05 '21 at 22:33
  • Uh, you didn't write a loop (loops generally have a `while`, `do while`, `for` or `foreach` keyword), so that's why it doesn't loop. As @PeterDuniho pointed out, make your function `async` and include `await Task.Delay` (instead of `Thread.Sleep`) and you won't freeze up your UI. – Flydog57 Jan 05 '21 at 23:10

0 Answers0