469,648 Members | 1,504 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,648 developers. It's quick & easy.

Modeless Dialog hangs

I am trying to create a modeless dialog from an event thread not generated from the original form. When created in one of the event handlers from the form, the dialog works properly. Also it works properly if it is a modal dialog.

I made this little example that will just pop up a modeless dialog (form2) after a second.
Here's some code....
Expand|Select|Wrap|Line Numbers
  1.  
  2. System.Timers.Timer timer = new System.Timers.Timer();
  3.         bool timer1 = false;
  4. Form2 c;
  5.  
  6. public Form1()
  7.         {
  8.             InitializeComponent();
  9.             timer.Interval = 1000;
  10.             timer.Elapsed += new System.Timers.ElapsedEventHandler(timertick);
  11.             timer.Start();
  12.         }
  13.         void timertick(object sender, System.Timers.ElapsedEventArgs e)
  14.         {
  15.             if (!timer1)
  16.             {
  17.                 ProcessEvent();
  18.                 timer1 = true;
  19.                 timer.Enabled = false;
  20.             }
  21.             else
  22.             {
  23.                 timer.Stop();
  24.             }
  25.         }
  26.  
  27.   private void ProcessEvent()
  28.         {
  29.             c = new Form2();
  30.             c.Show();                    
  31.          }
Apr 20 '10 #1
3 3559
tlhintoq
3,525 Expert 2GB
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.


UPDATE: You really did try and were very close. Sorry if my standard copy/paste reply to people who don't try at all sounded a bit cold. You had closed with \code instead of /code and the site parser didn't like the \ in place of / - No big deal, easy fixed
Apr 20 '10 #2
tlhintoq
3,525 Expert 2GB
I'm not sure I follow the exact nature of the problem.

Modeless Dialog hangs
by "hangs" are you saying that instance 'c' of Form2 opens, but doesn't close... opens but doesn't respond to user interaction... doesn't open...

I am trying to create a modeless dialog from an event thread not generated from the original form.
There is nothing in your code having to do with threading.
Apr 20 '10 #3
I fixed the issue by adding
Expand|Select|Wrap|Line Numbers
  1. private delegate void ModelessDialog(Arguments args);
  2.  
and changing
Expand|Select|Wrap|Line Numbers
  1. private void ProcessEvent()
  2. {
  3. if (this.InvokeRequired)
  4.             {
  5.                 this.Invoke(new ModelessDialog(ProcessEvent), null);
  6.             }
  7. else
  8. {
  9. c = new Form2(); 
  10.             c.Show(); 
  11. }
  12. }
  13.  
Thanks for the help.
Apr 20 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by Rikkert | last post: by
1 post views Thread by Carmine | last post: by
reply views Thread by Andrew | last post: by
1 post views Thread by andrew | last post: by
2 posts views Thread by proit_123 | last post: by
8 posts views Thread by proit_123 | last post: by
reply views Thread by Sin Jeong-hun | last post: by
3 posts views Thread by DoB | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.