Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Modeless dialog issue

Modeless dialog issue

Scheduled Pinned Locked Moved C#
testingbeta-testinghelpquestion
16 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A aei_totten

    I don't have anything in any of the handlers. It has pretty much nothing in it. I put one button on it that doesn't do anything. (I was just testing). The only code in it is the public ChatMessageForm() { InitializeComponent(); }

    R Offline
    R Offline
    Richard Blythe
    wrote on last edited by
    #4

    In this case, source code is the only thing that will help us solve your problem. This includes the code surrounding your chatMessageForm.Show() method.

    If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

    A 1 Reply Last reply
    0
    • R Richard Blythe

      In this case, source code is the only thing that will help us solve your problem. This includes the code surrounding your chatMessageForm.Show() method.

      If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

      A Offline
      A Offline
      aei_totten
      wrote on last edited by
      #5

      Well the code looks a bit like this..... public partial class ChatMessageForm : Form { public ChatMessageForm() { InitializeComponent(); } } private void ProcessChatMessageEvent() { ChatMessageForm c = new ChatMessageForm(); c.Show(); } ProcessChatMessageEvent is called by..... public void OnEvent(Object sender, EventPublisher.EventPublisherEventArgs eventArgs) { EventID nReceivedEvent = (EventID)eventArgs.iEventID; switch (nReceivedEvent) { case EventID.eChatMessageEvent: ProcessChatMessageEvent(); break; } } I checked and it works properly outside of the switch which kinda amazes me. (The OnEvent is a Cisco event handler)

      R 1 Reply Last reply
      0
      • A aei_totten

        I am trying to pop up a modeless dialog box using .Show() It does pop up the dialog, but it freezes and the components never load. I can open the same dialog with .ShowDialog() and it loads properly. But that doesn't accomplish what I am looking for in the dialog because i need it to be modeless. So, is there something that I am missing to make show work correctly? It is a pretty simple out of the box dialog that I am testing with, just from VS2008 designer with one button on it.

        G Offline
        G Offline
        Gregory Gadow
        wrote on last edited by
        #6

        The difference between Show and ShowDialog is that the first method displays the form and continues with the next line of code, while the second method pauses execution of the code until after the form has been closed. Observe:

        MyForm F = new MyForm();
        F.ShowDialog();
        System.Diagnostics.Debug.WriteLine("Output");

        In this case, the string Output will not be written to the Immediate window until the pop-up form is closed. If you replace F.ShowDialog() with F.Show(), Output will probably be written before the form finishes rendering. I suspect that your calling code needs to wait until the dialog has been handled, which is why ShowDialog works and Show does not. This can be a real pain if you are writing a MDI application, as child windows cannot be invoked with ShowDialog. Added: After looking at the code you posted above, I can see the problem. After calling Show(), the method ends. The variable referencing your form goes out of scope and gets recycled: your form is not getting a chance to render before it gets disposed. If it absolutely has to be modeless, you will need to move the scope of your form's variable out.

        A 2 Replies Last reply
        0
        • A aei_totten

          Well the code looks a bit like this..... public partial class ChatMessageForm : Form { public ChatMessageForm() { InitializeComponent(); } } private void ProcessChatMessageEvent() { ChatMessageForm c = new ChatMessageForm(); c.Show(); } ProcessChatMessageEvent is called by..... public void OnEvent(Object sender, EventPublisher.EventPublisherEventArgs eventArgs) { EventID nReceivedEvent = (EventID)eventArgs.iEventID; switch (nReceivedEvent) { case EventID.eChatMessageEvent: ProcessChatMessageEvent(); break; } } I checked and it works properly outside of the switch which kinda amazes me. (The OnEvent is a Cisco event handler)

          R Offline
          R Offline
          Richard Blythe
          wrote on last edited by
          #7

          aei_totten wrote:

          works properly outside of the switch

          Hmm, so your saying that the following code would work:

          public void OnEvent(Object sender, EventPublisher.EventPublisherEventArgs eventArgs)
          {
          //EventID nReceivedEvent = (EventID)eventArgs.iEventID;
          //switch (nReceivedEvent)
          //{
          //case EventID.eChatMessageEvent:

          ProcessChatMessageEvent();

          //break;
          //}
          }

          If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

          A 1 Reply Last reply
          0
          • G Gregory Gadow

            The difference between Show and ShowDialog is that the first method displays the form and continues with the next line of code, while the second method pauses execution of the code until after the form has been closed. Observe:

            MyForm F = new MyForm();
            F.ShowDialog();
            System.Diagnostics.Debug.WriteLine("Output");

            In this case, the string Output will not be written to the Immediate window until the pop-up form is closed. If you replace F.ShowDialog() with F.Show(), Output will probably be written before the form finishes rendering. I suspect that your calling code needs to wait until the dialog has been handled, which is why ShowDialog works and Show does not. This can be a real pain if you are writing a MDI application, as child windows cannot be invoked with ShowDialog. Added: After looking at the code you posted above, I can see the problem. After calling Show(), the method ends. The variable referencing your form goes out of scope and gets recycled: your form is not getting a chance to render before it gets disposed. If it absolutely has to be modeless, you will need to move the scope of your form's variable out.

            A Offline
            A Offline
            aei_totten
            wrote on last edited by
            #8

            Gregory.Gadow wrote:

            Added: After looking at the code you posted above, I can see the problem. After calling Show(), the method ends. The variable referencing your form goes out of scope and gets recycled: your form is not getting a chance to render before it gets disposed. If it absolutely has to be modeless, you will need to move the scope of your form's variable out.

            Now, that makes sense. However, in the real application, I have more demands of that form (I just wanted to get a simple one working first because I was running into this issue and couldn't pin point it). Here's some code.... private Dictionary<string, ChatMessageForm> chatMessages = new Dictionary<string, ChatMessageForm>(); ... string message, sender; message = "blah"; sender = "me"; if (!chatMessages.ContainsKey(sender)) { chatMessages.Add(sender, new ChatMessageForm(sender)); } chatMessages[sender].ShowDialog();} The Dictionary is declared outside of the process in the scope of the main form. However, i do think the issue is related. This is my first time using Dictionary so maybe I am missing something there...

            1 Reply Last reply
            0
            • R Richard Blythe

              aei_totten wrote:

              works properly outside of the switch

              Hmm, so your saying that the following code would work:

              public void OnEvent(Object sender, EventPublisher.EventPublisherEventArgs eventArgs)
              {
              //EventID nReceivedEvent = (EventID)eventArgs.iEventID;
              //switch (nReceivedEvent)
              //{
              //case EventID.eChatMessageEvent:

              ProcessChatMessageEvent();

              //break;
              //}
              }

              If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

              A Offline
              A Offline
              aei_totten
              wrote on last edited by
              #9

              Richard Blythe wrote:

              Hmm, so your saying that the following code would work:

              yes

              A 1 Reply Last reply
              0
              • G Gregory Gadow

                The difference between Show and ShowDialog is that the first method displays the form and continues with the next line of code, while the second method pauses execution of the code until after the form has been closed. Observe:

                MyForm F = new MyForm();
                F.ShowDialog();
                System.Diagnostics.Debug.WriteLine("Output");

                In this case, the string Output will not be written to the Immediate window until the pop-up form is closed. If you replace F.ShowDialog() with F.Show(), Output will probably be written before the form finishes rendering. I suspect that your calling code needs to wait until the dialog has been handled, which is why ShowDialog works and Show does not. This can be a real pain if you are writing a MDI application, as child windows cannot be invoked with ShowDialog. Added: After looking at the code you posted above, I can see the problem. After calling Show(), the method ends. The variable referencing your form goes out of scope and gets recycled: your form is not getting a chance to render before it gets disposed. If it absolutely has to be modeless, you will need to move the scope of your form's variable out.

                A Offline
                A Offline
                aei_totten
                wrote on last edited by
                #10

                Found out something else. Even without the Dictionary, just moving the declaration of the Form out into the scope of the main form was not enough to fix the problem

                R 1 Reply Last reply
                0
                • A aei_totten

                  Richard Blythe wrote:

                  Hmm, so your saying that the following code would work:

                  yes

                  A Offline
                  A Offline
                  aei_totten
                  wrote on last edited by
                  #11

                  well crud. I can't even reproduce that today :(

                  1 Reply Last reply
                  0
                  • A aei_totten

                    Found out something else. Even without the Dictionary, just moving the declaration of the Form out into the scope of the main form was not enough to fix the problem

                    R Offline
                    R Offline
                    Richard Blythe
                    wrote on last edited by
                    #12

                    Based on your last post, it seems that you need to look into the Cisco event behavior. For example, a standard windows event will not give you this behavior. Try trapping an event from your main form like this:

                    //...
                    public frmMain()
                    {
                    InitializeComponent();
                    frmMain.Click += new EventHandler(frmMain_Click);
                    }

                    ChatForm frmChat;
                    void frmMain_Click(object sender, EventArgs e)
                    {
                    if (frmChat == null)
                    {
                    frmChat = new ChatForm();
                    frmChat.Show();
                    }
                    frmChat.BringToFront();
                    }

                    If this works without a hitch (which it should), then you should contact Cisco and report a bug! :)

                    If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

                    A 1 Reply Last reply
                    0
                    • R Richard Blythe

                      Based on your last post, it seems that you need to look into the Cisco event behavior. For example, a standard windows event will not give you this behavior. Try trapping an event from your main form like this:

                      //...
                      public frmMain()
                      {
                      InitializeComponent();
                      frmMain.Click += new EventHandler(frmMain_Click);
                      }

                      ChatForm frmChat;
                      void frmMain_Click(object sender, EventArgs e)
                      {
                      if (frmChat == null)
                      {
                      frmChat = new ChatForm();
                      frmChat.Show();
                      }
                      frmChat.BringToFront();
                      }

                      If this works without a hitch (which it should), then you should contact Cisco and report a bug! :)

                      If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

                      A Offline
                      A Offline
                      aei_totten
                      wrote on last edited by
                      #13

                      Thanks for the relpy. It does work fine from a button event or other main form generated event. However, I created a System.Timers.Timer and called the method from it's elapsed event handler and that created the same freeze as seen from the Cisco event handler.

                      R 1 Reply Last reply
                      0
                      • A aei_totten

                        Thanks for the relpy. It does work fine from a button event or other main form generated event. However, I created a System.Timers.Timer and called the method from it's elapsed event handler and that created the same freeze as seen from the Cisco event handler.

                        R Offline
                        R Offline
                        Richard Blythe
                        wrote on last edited by
                        #14

                        Okay, maybe it's a thread issue. Most of my apps doesn't required thread sensitive code. Try using thread context code like this:

                        //Cisco event handler (can't rem it's method def)
                        ...
                        {
                        InvokeMethod();
                        }

                        private delegate void EmptyHandler();
                        private void InvokeMethod()
                        {
                        if (this.InvokeRequired) // 'this' is frmMain
                        this.Invoke(new EmptyHandler(InvokeMethod), null);
                        else
                        {
                        ChatForm frmChat = new ChatForm();
                        frmChat.Show();
                        }
                        }

                        This create the new chat for on the same thread as the main form. Maybe a long shot, but it may be what your looking for... Cheers, Richard

                        If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

                        A 1 Reply Last reply
                        0
                        • R Richard Blythe

                          Okay, maybe it's a thread issue. Most of my apps doesn't required thread sensitive code. Try using thread context code like this:

                          //Cisco event handler (can't rem it's method def)
                          ...
                          {
                          InvokeMethod();
                          }

                          private delegate void EmptyHandler();
                          private void InvokeMethod()
                          {
                          if (this.InvokeRequired) // 'this' is frmMain
                          this.Invoke(new EmptyHandler(InvokeMethod), null);
                          else
                          {
                          ChatForm frmChat = new ChatForm();
                          frmChat.Show();
                          }
                          }

                          This create the new chat for on the same thread as the main form. Maybe a long shot, but it may be what your looking for... Cheers, Richard

                          If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

                          A Offline
                          A Offline
                          aei_totten
                          wrote on last edited by
                          #15

                          That did it. I had tried previously checking if the dialog needed invoke but i didn't check this.invokerequired Thanks so much!

                          R 1 Reply Last reply
                          0
                          • A aei_totten

                            That did it. I had tried previously checking if the dialog needed invoke but i didn't check this.invokerequired Thanks so much!

                            R Offline
                            R Offline
                            Richard Blythe
                            wrote on last edited by
                            #16

                            Great! I was a pro and didn't even know it. :laugh: Maybe you'll have the answer for me when I need it.

                            If my answer has helped you, one of my articles may also be a help. Also remember that your best friend's name is google.

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups