I have the following situation, I have a Form app that needs to load a lot of UI controls. I have a loading animation that it is over every other control. I want the animation stay above and running while the loading process occurs. At the end of the process the panel with the animation could dissapear.
As the UI is very busy creating and positioning every new control only the box where the panel is positioning appears. The animation never moves. (A gif image).
If I disable the form as I read in a related SO question, I could see the panel with the gif but it doesn't move. It remain static and greyed.
I made an attempt to run another form with the animation above the other busy form but the way that I made it sometimes work and sometimes don't.
ReallyBusyForm.Show();
ReallyBusyForm.Focus();
var floatingWindow = new FloatingLoadingWindow();
Task.Run(() => floatingWindow.ShowDialog());
await Task.Run(() => ReallyBusyForm.LoadYourControls());
Invoke((MethodInvoker)(() =>
{
while (Application.OpenForms["FloatingLoadingWindow"] == null)
{
Thread.Sleep(200);
}
floatingWindow.Close();
}));
I think that sometimes work and sometimes don't due that there is non warranty that the floatingWindow.ShowDialog() ran before the loading of controls. If it ran before I have the visual effect that I need. If it ran after I see how the ReallyBusyForm is creating and adding every child control. If I do a synchronious call then I block the load of controls.
floatingWindow.ShowDialog(); //this call obviously block the execution of what comes next
await Task.Run(() => ReallyBusyForm.LoadYourControls());
In consequence I need a proper way to show a loading animation when open a form that is very busy creating its child controls.