在一个窗体(主窗体)初始化的时候,会调用另一个窗体得到一堆起始输入,然后传递很多信息:
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;
但这也会导致它挂起。也许出于同样的原因。我调查了自动重置事件。
我试过:
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;
这将暂停执行,只有在表单关闭后才会继续。
关于c# - 等待从弹出表单中获取信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12007541/