First, if you want to delay any of this computation until after the form is displayed, you should trigger that computation in the handler for the
Shown
event instead of the
Load
event.
(See:
Form.Shown Event (System.Windows.Forms)[
^])
Next, you didn't answer my earlier question about whether or not the results of the
Global
and
ChildAccess
methods are shared by the
sr_created
and
sr_solved
methods, or if they need to be called independently by
sr_created
and
sr_solved
.
I'm going to assume the results are shared and that
sr_created
and
sr_solved
should not be executed until
Global
and
ChildAccess
have completed.
Also, you haven't said if the UI should block while all of this computation is running (I'll assume no) and if there is something that should happen when the computation of
sr_created
and
sr_solved
have completed (I'll assume yes).
So try something like this:
(Note: untested! Coded "off the top of my head" (with some research).)
private void overview_Shown(object sender, EventArgs e)
{
ComputationChain().ContinueWith(DoAfterComputationCompleted);
}
private Task ComputationChain()
{
return PreworkComputation().ContinueWith(_ =>
Task.WaitAll(
Task.Run((Action)SrCreated),
Task.Run((Action)SrSolved)));
}
private Task PreworkComputation()
{
return Task.WhenAll(
Task.Run((Action)Global),
Task.Run((Action)ChildAccess));
}
private Task PreworkComputation()
{
return Task.Run(() => {
Global();
ChildAccess();
});
}
void SrCreated()
{
}
void SrSolved()
{
}
void Global()
{
}
void ChildAccess()
{
}
private void DoAfterComputationCompleted(Task _)
{
this.Invoke(() => {
});
}