How to implement a timer that every cycle updates a listbox in C #;
Method to create the timer:
private void CriaTimer()
{
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += OnTimedEvent;
aTimer.Interval = 100;
aTimer.Enabled = true;
}
private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
AtualizaControlesForm();
}
Method to update components:
public void AtualizaControlesForm()
{
Invoke(new MethodInvoker(() => this.lblPorcentagemGeracao.Text = UtilidadesGeraSped.valorProgressoGeracao + "%"));
Invoke(new MethodInvoker(() => this.listBoxInformacoesLog.DataSource = Mensagens.logErroseInfo));
Invoke(new MethodInvoker(() => this.listBoxInformacoesLog.Refresh()));
}
You are updating textLabel, but it does not update the listBox;