I have a form where I use data from API. While getting data from server the form is blocked. I try to use async await and tasks but it does not help. The form is blocked anyway. Can you please explain how I can apply the async await in my app?
The code I use:
private void navigationTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
Task task = SwitchToProjectsPanelAsync();
task.Wait();
}
private async Task SwitchToProjectsPanelAsync()
{
CurrentPanel.Visible = false;
if (MyAllProjectsFlowLayoutPanel == null)
{
MyAllProjectsFlowLayoutPanel = new MyAllProjectsFlowLayoutPanel(this);
MyAllProjectsFlowLayoutPanel.SuspendLayout();
this.Controls.Add(MyAllProjectsFlowLayoutPanel);
MyAllProjectsFlowLayoutPanel.AllProjects = _controller.GetProjectsList();
MyAllProjectsFlowLayoutPanel.ShowProjectsList();
CurrentPanel = MyAllProjectsFlowLayoutPanel;
CurrentPanel.Visible = true;
MyAllProjectsFlowLayoutPanel.ResumeLayout(false);
MyAllProjectsFlowLayoutPanel.PerformLayout();
}
else
{
CurrentPanel = MyAllProjectsFlowLayoutPanel;
CurrentPanel.Visible = true;
}
}
Full code is on Git https://github.com/ViktorKuryshev/CRM