I have tried what I saw in this post, which did not answer my question. See my code and further explanation below.
// In MyForm : Form
private void SetupForImportantTask()
{
// Does a ton of stuff to set up for ImportantTask, then...
this.Close();
}
private void MyForm_FormClosed(object sender, FormClosedEventArgs e)
{
// otherForm is an instance of OtherForm : Form
otherForm.ImportantTask(variousData);
}
// In OtherForm class...
public void ImportantTask(object variousData) {
// Does a bunch of stuff that takes a long time
// Provides UI feedback to notify the user a process in under way
}
Explanation: As you can see in the code, the idea is to do a bunch of setup for ImportantTask
in MyForm
, then call back into OtherForm
with the setup information established after MyForm
has already closed.
What I am seeing instead:
Even though I am not calling ImportantTask
until the Closed
event on MyForm
has already fired, meaning semantically that the Form is already closed, MyForm
remains open while the UI thread hangs, until ImportantTask
is complete. The UI notification of the long-running process is never displayed, and MyForm
only closes after ImportantTask
is complete.
If MyForm
is not closed when the Closed
event fires, how else can I determine that the Form is actually closed and cleared from the screen?
Or:
What silly thing have I missed?