ShowDialog and Control.Invoke

  • Thread starter Thread starter Ian Williamson
  • Start date Start date
Thanks, but it doesn't work. I never return from the invoke call. Not until
after the dialog is dismissed.
-jim
 
A code snippet would be to large, but it is easy to reproduce. Go get the
threading quickstart for the compact framework...
http://samples.gotdotnet.com/quickstart/CompactFramework/doc/controlinvoker.aspx

Download the C# code and make a project/solution for it. Build and run. It
runs great.

Now add a new form that will be your main window. Add two buttons "Modal"
and "Modeless". Implement the buttons' Click() event methods as follows...

private void btnModal_Click(object sender, System.EventArgs e)
{
ControlInvokerSample.Form1 dialog = new ControlInvokerSample.Form1();
dialog.ShowDialog();
}

private void btnModless_Click(object sender, System.EventArgs e)
{
ControlInvokerSample.Form1 dialog = new ControlInvokerSample.Form1();
dialog.Show();
}

Next change Main() to load the new form as the main window (instead of the
CountDown form). Build and run. If you click the Modeless button every thing
works. If you click the Modal button the thread stalls.

Thanks again,
-jim
 
I have a similar problem with threads and ShowDialog, I start a thread to
retreive information to stick in a list view. but sometimes the invoke of
my deligate doesnt occure untill the dialog is closed. I was able to fix
this by calling DoEvents immediately after starting the thread, but I dont
think thats a garenteed result. Also, my fix only worked with sp1
installed.
 
Tibor,

Great.

What device are you testing against? Is it possible to send me your test
directly ([email protected]) so I can test on my setup? Perhaps you did
something different then I did.

Thanks,
-jim
 
Jim,

I did exactly, what you have suggested (downloading the
sample, creating a new form with the 2 buttons...).
I have a Symbol device running Pocket PC and I have
installed the CF Service Pack 1.
Actually I am doing something similar in a project:
I have set up a hook for keyboard events, which notifies
a subclassed MessageWindow in managed code. Then I send
the message to the active form in a separate thread, and
from this thread I do some UI actions (sometimes I even
show up a new modal dialog), and it works fine.

Tibor
 
Back
Top