3
I’m doing a small XAML application that asks for 2 dates. Dates are passed as a parameter to some methods invoked by the Event click button. The problem is that during the execution of the methods the form remains locked.
Using Backgroundworker or another Threads feature to solve this problem?
private void Button_Click(object sender, RoutedEventArgs e)
{
DateTime dataInicial = new DateTime();
DateTime dataFinal = new DateTime();
dataInicial = (DateTime)dtInicial.SelectedDate;
dataFinal = (DateTime)dtFinal.SelectedDate;
progressbar1.Visibility = Visibility.Visible;
progressbar1.IsIndeterminate = true;
thread = new Thread(() => {
relatorio1 r1 = new relatorio1();
r1.gerarDados(dataInicial, dataFinal);
relatorio2 r2 = new relatorio2();
r2.gerarDados(dataInicial, dataFinal);
relatorio3 r3 = new relatorio3();
r3.gerarDados(dataInicial, dataFinal);
relatorio4 r4 = new relatorio4();
r4.gerarDados(dataInicial, dataFinal);
MessageBox.Show("Sucesso !!!");
});
thread.Start();
progressbar1.IsIndeterminate = false;
}
In the current code I solved the locking problem by instantiating a Thread directly through Lambda. The problem is that I can’t change the Form Progressibar properties once the Thread Ends. I would like to set the Isindeterminate event to false but I did not succeed. I believe that with Backgroundworker it is possible.
Thanks Roney, funfou ! Thanks for the button tip, I chose to disable it during processing.
– Raphael Teodoro