Great problem with async/await
Hi, I am doing a simple simulation of the classic game "rock-paper-scissors". The problem when using the "Styles / Controls.xaml" file and load a ListView from an asynchronous method or not, the GUI is frozen until the loop ends. If I use the default WPF controls, I do not have this problem. Any ideas?
I suppose this is a bug in your code rather than a MahApps.Metro problem. If the GUI freezes while using an asychronous method, you might want to try data binding.
Thanks for answering.
- If I use the default controls for WPF, I do not have that problem.
- I solved for now, adding to the ListView "Style = {x: Null}" but do not think is the most optimal.
This is a part of my code
private RelayCommand _jugarCommand; public RelayCommand JugarCommand { get { return _jugarCommand ?? (_jugarCommand = new RelayCommand(Jugar)); } }
private async void Jugar() { Jugadas = await CalcularJugadas(); }
private Task<ObservableCollection<Jugada>> CalcularJugadas()
{
return Task.Run(
() =>
{
var calcularJugadas = new ObservableCollection<Jugada>();
for (var iIndex = 1; iIndex <= Convert.ToInt16(CantidadDeSimulaciones); iIndex++)
{
}
return calcularJugadas;
}
);
}
@avechuche You can load data in Jugadas using a async background worker.
see https://github.com/MahApps/MahApps.Metro/issues/2000 for background worker code.