C# 在NETCF上实现InputBox

C# 在NETCF上实现InputBox,c#,multithreading,compact-framework,inputbox,C#,Multithreading,Compact Framework,Inputbox,我正在为Windows Mobile开发一个应用程序。它包含一个主窗体,用户界面由单个用户控件实现。当用户单击Menu>ShipProduct时,ShipProduct用户控件将添加到主窗体控件数组中并显示。一旦用户在ShipProduct UC上,我想为他们提供InputBox功能。这是我试过的。除了将InputBox添加到主窗体的委托,它永远不会返回。我假设这是因为are.WaitOne与UI位于同一线程上 我需要做什么才能实现这一点 我找到了一份使用YieldAwait图书馆的工作http

我正在为Windows Mobile开发一个应用程序。它包含一个主窗体,用户界面由单个用户控件实现。当用户单击Menu>ShipProduct时,ShipProduct用户控件将添加到主窗体控件数组中并显示。一旦用户在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>

问题是我只使用了1个主窗体。UserControl.ShowDialog更符合我的要求。谢谢,不过你说得对。我正在将我的解决方案更改为执行form.showdialog,而不是与UserControl混为一谈。