1

I'm developing an app for Windows Mobile. It contains one main Form and user UI is implemented with individual UserControls. When the user clicks on Menu > Ship Product, the ShipProduct UserControl is added to the main forms Controls array and is shown. Once a user is on the ShipProduct UC, I would like to provide them with InputBox functionality. Here is what I have tried (pseudo). Except the delegate that adds the InputBox to the main form never returns. I am assuming that is because are.WaitOne() is on the same thread as the UI.

What do I need to do to be able to implement this?

I have found a work around using the YieldAwait library (http://yieldawait.codeplex.com), but it is turning out to be a very complicated solution.

<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>
fixitchris
  • 90
  • 7
  • The problem is that I am only using 1 main form. UserControl.ShowDialog() is more of what I am looking for. Thanks. – fixitchris Jul 28 '11 at 20:06
  • You're right though. I'm changing my solution to do form.showdialog instead of messing around with the UserControl. – fixitchris Jul 28 '11 at 20:19

0 Answers0