1

Sorry for my little English

I have a problem Instead of the timer, I need to run the codes below in a loop. can you help me with this my main purpose to use thread or async

 if (NumbersIndexCounter != PhoneNumbersList.Count)
            {
                SendMessage(PhoneNumbersList[NumbersIndexCounter++]);
            }
            lblFailedProcess.Text = FailedProcess.ToString();
            lblSuccedProcess.Text = SuccedProcess.ToString();
            //metroLabel2.Text = toplamprocess.ToString();
            Thread.Sleep(2000);
            dataGridİnfos.DataSource = "";
            dataGridİnfos.DataSource = InfoList;
            Thread.Sleep(Convert.ToInt16(txtWaitBeforeEveryMessage.Text)*1000);
            ProcessCounter++;

            if (NumbersIndexCounter == PhoneNumbersList.Count)
            {
                int s1, s2;
                s1 = Convert.ToInt32(lblFailedProcess.Text);
                s2 = Convert.ToInt32(lblSuccedProcess.Text);
                int toplam = s1 + s2;
                metroLabel2.Text = "Toplam = " + toplam;
                timer1.Stop();
                Driver.Quit();
                MessageBox.Show("Bitti!");
                NumbersIndexCounter = 0;
                grpBxMessage.Enabled = true;
                grpBxPhoneNumbers.Enabled = true;
                grpBxSettings.Enabled = true;
                PhoneNumbersList.Clear();
            }

            if (ProcessCounter == Convert.ToInt32(txtMessageCountForWait.Text))
            {                
                Thread.Sleep(Convert.ToInt16(txtWait.Text) * 1000);
                ProcessCounter = 0;
            }

but when I use a private void in my codes, it works once and does not continue. When I use a timer, it works without any problems, but the form is not response.

  • 2
    I see no async here or loop – TheGeneral Oct 29 '21 at 06:53
  • Why do you not want to use a timer? – JonasH Oct 29 '21 at 07:55
  • When I use timer with theread, it doesn't work, so I can't run my codes in timer with theread, either I need to use it with async or thread or I have to update these codes with a loop. – Umut Güneş Oct 29 '21 at 08:46
  • why i don't want to use timer because form freezes i don't know how to use backgroundworker so i gave my codes these codes need to run in background – Umut Güneş Oct 29 '21 at 08:48
  • I think you are confused about how timers work. Using `Thread.Sleep` on the main thread will freeze the UI regardless of using a timer or anything else. I would suggest explaining what you are trying to do in the first place, and a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) would also help. – JonasH Oct 29 '21 at 09:25
  • https://stackoverflow.com/questions/54958184/why-selenium-webdriver-freezes-the-windows-form-appliaction/54987097 – Umut Güneş Oct 29 '21 at 10:22
  • This is exactly what I want. I want to use the codes I gave above before my form freezes. – Umut Güneş Oct 29 '21 at 10:23

0 Answers0