1

我正在为 Windows Mobile 开发一个应用程序。它包含一个主窗体,用户 UI 是通过单独的 UserControls 实现的。当用户单击 Menu > Ship Product 时,ShipProduct UserControl 被添加到主窗体 Controls 数组中并显示出来。一旦用户使用 ShipProduct UC,我想为他们提供 InputBox 功能。这是我尝试过的(伪)。除了将 InputBox 添加到主窗体的委托永远不会返回。我假设这是因为 are.WaitOne() 与 UI 在同一个线程上。

我需要做什么才能实现这一点?

我找到了使用 YieldAwait 库 (http://yieldawait.codeplex.com) 的工作,但结果证明这是一个非常复杂的解决方案。

<pre>
Main()
{
   MainForm form = new MainForm();
   Application.Run(form);
}

MainForm: Form
{
   public AutoResetEvent are = new AutoResetEvent(false);

   Menu_click()
   {
      this.Controls.Add(new ShipProduct)
   }
}

InputBox: UserControl
{
    OK_Button_click()
    {
       form.are.Set();

    }

}

ShipProduct: UserControl
{


  void GetUserInput()
  {


     Thread t = new Thread(ShowInputBox);
     t.Start();
     form.are.WaitOne();

  }

  void ShowInputBox()
  {
     InputBox ib = new InputBox();
     form.Invoke
     (
       delegate {
                  form.Controls.Add(ib);
                  ib.Show();
                } 
       /***/
       // delegate never returns!
     )
  }

}
</pre>
4

0 回答 0