Modeless Dialog hangs

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • btotten
    New Member
    • Apr 2010
    • 2

    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....
    Code:
                 
    System.Timers.Timer timer = new System.Timers.Timer();
            bool timer1 = false;
    Form2 c;
    
    public Form1()
            {
                InitializeComponent();
                timer.Interval = 1000;
                timer.Elapsed += new System.Timers.ElapsedEventHandler(timertick);
                timer.Start();
            }
            void timertick(object sender, System.Timers.ElapsedEventArgs e)
            {
                if (!timer1)
                {
                    ProcessEvent();
                    timer1 = true;
                    timer.Enabled = false;
                }
                else
                {
                    timer.Stop();
                }
            }
    
      private void ProcessEvent()
            {
                c = new Form2();
                c.Show();                    
             }
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you first created your question you were asked to wrap your code with [code] tags.
    [imgnothumb]http://files.me.com/tlhintoq/10jihf[/imgnothumb]
    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

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      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.

      Comment

      • btotten
        New Member
        • Apr 2010
        • 2

        #4
        I fixed the issue by adding
        Code:
        private delegate void ModelessDialog(Arguments args);
        and changing
        Code:
        private void ProcessEvent()
        {
        if (this.InvokeRequired)
                    {
                        this.Invoke(new ModelessDialog(ProcessEvent), null);
                    }
        else
        {
        c = new Form2(); 
                    c.Show(); 
        }
        }
        Thanks for the help.

        Comment

        Working...