Wait to get info from a popup form

Viewed 11788

At initialization of a form (the main form), it calls another form to get a bunch of starting input, and then transfers a lot of information:

Form3 getup = new Form3();
getup.Show();
example = getup.example;

However, I need to wait for this new form information to be complete.

Form3 getup = new Form3();
getup.Show();
waitfordone();
example = getup.example;

ATM, I've tried using while statements:

Form3 getup = new Form3();
getup.Show();
While(getup.visible=true)Console.WriteLine("waiting");
example = getup.example;

But this causes a hang... that is to say, it runs, then freezes. I suspect this is because the while loop is eating all the processing. So, I tried making a new thread

Form3 getup = new Form3();
Thread t = new Thread(getup.Show());
t.start();
While(getup.visible=false)Console.WriteLine("waiting"); // takes a little bit to open
While(getup.visible=true)Console.WriteLine("waiting"); //waits for close
example = getup.example;

But this also causes it to hang. Perhaps for the same reason. I have looked into autoresetevents.

And I tried:

AutoResetEvent invisible = new AutoResetEvent(false);
Form3 getup = new Form3();
void setup_invisible(object sender, EventArgs e)
{
    if (getup.Visible == false) invisible.Set();
}
public ... {
getup.VisibilityChanged += new EventHandle(setup_Invisible);
getup.show();
invisible.WaitOne();
... }
// and many other variations on this

but alas, it opens form3, closes it (because the thread is done?), and then hangs at invisible.WaitOne();

Can someone please explain how to do this, reading is only making me more confused.

2 Answers
Related