dimanche 6 janvier 2019

How to iterate through a list of object on timer_tick event?

I have a list

static List<Participants> soop = ParticipantRepository.GetAllParticipants();

It has some 800 items. Then there's a label and a timer. At timer_tick, I want to display one of the items randomly. Here's the code for that event

private void timer1_Tick(object sender, EventArgs e) {
            foreach (var participants in soop)
            {
                a = participants.RollNumber;
                label1.Text = a;
                break;
            }
            counter++;
            if (counter == 200) {
                timer1.Stop();
                pictureBox5.Visible = false;
                counter = 0;
            }
        }

I have not been able to achieve the random functionality so far because only one RollNumber is being displayed and then the timer takes its time and runs out. What am I doing wrong?




Aucun commentaire:

Enregistrer un commentaire