I'm making a small XAML application that requests 2 dates. Dates are passed as a parameter to some methods invoked by the Button click event. The problem is that during the execution of the methods the form remains locked.
How to use the BackgroundWorker or other Threads feature to solve this problem?
privatevoidButton_Click(objectsender,RoutedEventArgse){DateTimedataInicial=newDateTime();DateTimedataFinal=newDateTime();dataInicial=(DateTime)dtInicial.SelectedDate;dataFinal=(DateTime)dtFinal.SelectedDate;progressbar1.Visibility=Visibility.Visible;progressbar1.IsIndeterminate=true;thread=newThread(()=>{relatorio1r1=newrelatorio1();r1.gerarDados(dataInicial,dataFinal);relatorio2r2=newrelatorio2();r2.gerarDados(dataInicial,dataFinal);relatorio3r3=newrelatorio3();r3.gerarDados(dataInicial,dataFinal);relatorio4r4=newrelatorio4();r4.gerarDados(dataInicial,dataFinal);MessageBox.Show("Sucesso !!!");
});
thread.Start();
progressbar1.IsIndeterminate = false;
}
In the current code I solved the crash problem by instantiating a Thread directly through Lambda. The problem is that I can not change the ProgressBar properties of the Form as soon as the Thread ends. I would like to set the IsIndeterminate event to false but I did not succeed. I believe Backgroundworker is possible.