I am working with a WPF application and I am facing problems while applying Navigation, the screen freezes , So I want to achieve Asynchronicity
My method of navigation : I create a grid and add User controls to the children property of that grid and since I have so many UI elements on numerous different User controls it freezes the Application
I want to add A user control asynchronous on when the window is loaded, My idea is to use the async await keywords but obviously I am using them incorrectly, I have researched and do not understand why it is suggested to use dispatcher even after there being async await so I wanted to follow that way (async/await)
This is just a sample problem of the real deal
this is the code
private async void grid1_Loaded(object sender, RoutedEventArgs e)
{
txtb1.Text = "";
var watch = System.Diagnostics.Stopwatch.StartNew();
await gy();
watch.Stop();
var elapsedtm = watch.ElapsedMilliseconds;
txtb1.Text += $"TOTAL TIME {elapsedtm} \n\n\n";
}
private async Task gy()
{
////////////
Y1 child1 = new Y1();
await Task.Run(() => grid1.Children.Add(child1));
///////////
}