0
How to implement a timer that updates a listbox in c every cycle#;
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()));
}
Is updating the textLabel, but does not update the listbox;
This is looking so funny.
– Maniero
Why do you update the list every X seconds and not when the list is actually modified? You are using WPF or Windows Forms?
– vinibrsl
How do I update every modification? I’m using Windows Forms
– Victor Freitas