在表单(主表单)初始化时,它调用另一个表单以获取一堆起始输入,然后传输大量信息:

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

但是,我需要等待此新表格信息完成。
Form3 getup = new Form3();
getup.Show();
waitfordone();
example = getup.example;

ATM,我尝试使用while语句:
Form3 getup = new Form3();
getup.Show();
While(getup.visible=true)Console.WriteLine("waiting");
example = getup.example;

但是,这会导致挂起……也就是说,它挂起,然后卡住。我怀疑这是因为while循环正在占用所有处理。因此,我尝试创建一个新线程
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;

但这也导致它挂起。也许出于同样的原因。我研究了autoresetevents。

我试过了:
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

但可惜的是,它打开了form3,将其关闭(因为线程完成了?),然后卡在invisible.WaitOne();

有人可以解释一下该怎么做,阅读只会让我更加困惑。

最佳答案

您可能需要一个对话框。

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

这将暂停执行,并且仅在关闭表单后才继续执行。

10-08 07:25
查看更多