does ShowDialog start new thread ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • shark

    does ShowDialog start new thread ?

    Hi,

    Does Form.ShowDialog () start new thread ?
    If yes how is solved cross-thread operations?

    Thx
  • =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?=

    #2
    Re: does ShowDialog start new thread ?

    shark wrote:
    Hi,
    >
    Does Form.ShowDialog () start new thread ?
    If yes how is solved cross-thread operations?
    >
    Thx
    No, it doesn't.

    --
    Lasse Vågsæther Karlsen
    mailto:lasse@vk arlsen.no
    Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

    PGP KeyID: 0xBCDEA2E3

    Comment

    • Aneesh Pulukkul [http://dotnet-revolutions.blogspo

      #3
      Re: does ShowDialog start new thread ?

      On May 5, 4:26 pm, Lasse Vågsæther Karlsen <la...@vkarlsen .nowrote:
      shark wrote:
      Hi,
      >
      Does Form.ShowDialog () start new thread ?
      If yes how is solved cross-thread operations?
      >
      Thx
      >
      No, it doesn't.
      >
      --
      Lasse Vågsæther Karlsen
      mailto:la...@vk arlsen.nohttp://presentationmod e.blogspot.com/
      PGP KeyID: 0xBCDEA2E3
      I was under a notion that Show and ShowDialog would executeon a
      different thread. Seems interesting..Th anks Lasse.

      Comment

      • Robin

        #4
        Re: does ShowDialog start new thread ?

        On 5月5日, 下午7时29分 , "Aneesh Pulukkul [http://dotnet-
        revolutions.blo gspot.com]" <anees...@gmail .comwrote:
        On May 5, 4:26 pm, Lasse Vågsæther Karlsen <la...@vkarlsen .nowrote:
        >
        shark wrote:
        Hi,
        >
        Does Form.ShowDialog () start new thread ?
        If yes how is solved cross-thread operations?
        >
        Thx
        >
        No, it doesn't.
        >
        --
        Lasse Vågsæther Karlsen
        mailto:la...@vk arlsen.nohttp://presentationmod e.blogspot.com/
        PGP KeyID: 0xBCDEA2E3
        >
        I was under a notion that Show and ShowDialog would executeon a
        different thread. Seems interesting..Th anks Lasse.
        Every window should have a thread to process messages, right?

        Comment

        • Paul E Collins

          #5
          Re: does ShowDialog start new thread ?

          "Aneesh Pulukkul [http://dotnet-revolutions.blo gspot.com]"
          <aneesh.p@gmail .comwrote:
          I was under a notion that Show and ShowDialog would executeon a
          different thread.
          Try putting code after ShowDialog. It won't run until that second window
          closes. If ShowDialog just launched another thread, the code after
          ShowDialog would run immediately.

          Eq.


          Comment

          • shark

            #6
            Re: does ShowDialog start new thread ?

            Hmm, I think that this is not a proof, because each modal window have it's
            own message queue and that's why code after ShowDialog will not execute.


            "Paul E Collins" <find_my_real_a ddress@CL4.orgw rote in message
            news:fpqdnUwdJJ FfkILVnZ2dnUVZ8 u6dnZ2d@bt.com. ..
            "Aneesh Pulukkul [http://dotnet-revolutions.blo gspot.com]"
            <aneesh.p@gmail .comwrote:
            >
            >I was under a notion that Show and ShowDialog would executeon a different
            >thread.
            >
            Try putting code after ShowDialog. It won't run until that second window
            closes. If ShowDialog just launched another thread, the code after
            ShowDialog would run immediately.
            >
            Eq.
            >
            >

            Comment

            • Chris Shepherd

              #7
              Re: does ShowDialog start new thread ?

              shark wrote:
              Hi,
              >
              Does Form.ShowDialog () start new thread ?
              If yes how is solved cross-thread operations?
              This may not be a perfect test, but I just ran a simple form with a CancelButton
              setup using ShowDialog(), and had the threads window open in VS2005 (Debug ->
              Windows -Threads) and no new threads appeared to spawn to handle the dialog.

              There may be other reasons why that happened though.

              Chris.

              Comment

              • Peter Duniho

                #8
                Re: does ShowDialog start new thread ?

                On Mon, 05 May 2008 05:19:41 -0700, Robin <zouyongbin@gma il.comwrote:
                Every window should have a thread to process messages, right?
                Wrong. A thread that owns one or more windows will have a single message
                pump loop that dispatches messages to _all_ windows owned by that thread.

                Comment

                • Peter Duniho

                  #9
                  Re: does ShowDialog start new thread ?

                  On Mon, 05 May 2008 07:27:21 -0700, shark <mark@poczta.on et.plwrote:
                  Hmm, I think that this is not a proof, because each modal window have
                  it's own message queue and that's why code after ShowDialog will not
                  execute.
                  Why do you think each modal window has its own message queue?

                  There's a single queue per thread, messages for all windows owned by that
                  thread are placed in the queue, and a given thread will have a single
                  message pump loop active at any given time. Your premise is false, so no
                  conclusion based on premise that could be useful.

                  As for why code after ShowDialog() doesn't execute until the window is
                  closed...

                  In the case of a modal window, the modal code that handles displaying the
                  window runs its own message pump loop and doesn't return until the window
                  is closed. That's why the code after ShowDialog() won't execute until the
                  window is closed.

                  But the message pump loop handling the modal window is running on the same
                  thread in which you called ShowDialog(), and will dispatch messages to
                  _all_ windows owned by that thread, not just the modal window that was
                  displayed.

                  Pete

                  Comment

                  • shark

                    #10
                    Re: does ShowDialog start new thread ?

                    So in our cases we have two windows: first is main form window and the
                    second in modal dialog.

                    Are they created in the same thread?
                    How many message pump do we have in this case (seems like 2)?




                    "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
                    news:op.uaoweib 78jd0ej@petes-computer.local. ..
                    On Mon, 05 May 2008 05:19:41 -0700, Robin <zouyongbin@gma il.comwrote:
                    >
                    >Every window should have a thread to process messages, right?
                    >
                    Wrong. A thread that owns one or more windows will have a single message
                    pump loop that dispatches messages to _all_ windows owned by that thread.

                    Comment

                    • Peter Duniho

                      #11
                      Re: does ShowDialog start new thread ?

                      On Mon, 05 May 2008 23:04:11 -0700, shark <mark@poczta.on et.plwrote:
                      So in our cases we have two windows: first is main form window and the
                      second in modal dialog.
                      >
                      Are they created in the same thread?
                      Impossible to answer without seeing the code. The windows are created in
                      whatever thread executes the code that creates them. But by default,
                      without you introducing an additional thread to the picture, yes...the
                      modal dialog would be created on the same thread as any other window.
                      How many message pump do we have in this case (seems like 2)?
                      Why do you say "seems like 2"? Assuming the modal dialog is created in
                      the same thread as the main form window, then there will only be a single
                      message pump running at a given time. When the modal dialog is being
                      shown, the message pump that handles the modal nature of the dialog will
                      be pumping messages for _all_ windows that had been created on that thread.

                      If you create the modal dialog on a different thread, then you'll have two
                      message pumps: the main GUI thread's pump, and the one that's started when
                      you show the modal dialog. But so far you haven't given any reason for us
                      to believe that the modal dialog is created on a different thread.

                      If you have some specific code to show, it will be possible to tell you
                      whether more than one thread is involved. Otherwise, it won't be possible
                      to say for sure. But generally speaking, if you are showing a modal
                      dialog in response to some event raised by an existing Control instance
                      (including, for example, a form), without delegating that work to some
                      other thread, the modal dialog will be created on the same thread in which
                      that existing Control instance was created.

                      Pete

                      Comment

                      • André Luiz Sobreiro

                        #12
                        Re: does ShowDialog start new thread ?



                        I had a problem similar to this, and I am still looking for the
                        solution.

                        I have an MDI form, instantiating a child form, calling the ShowDialog
                        method.

                        I works fine. Ithe problem is when the form is embbeded on a second
                        assembly, when it happens, it realy seems to start another thead,
                        becouse it don´t wait the window to close to continue the next step of
                        the procedure.

                        any idea?

                        Thanks and regards,
                        André Luiz Sobreiro

                        *** Sent via Developersdex http://www.developersdex.com ***

                        Comment

                        • Jeff Winn

                          #13
                          Re: does ShowDialog start new thread ?

                          ShowDialog pauses the calling thread execution until the form has closed,
                          Show does not. ShowDialog would not be able to return the proper dialog
                          result if the thread continued processing. I don't see how putting the class
                          in another assembly would make any difference at all.

                          Perhaps you have a background thread that is closing the form on you.

                          "André Luiz Sobreiro" <sobreiro@yahoo .comwrote in message
                          news:OLfQHZV1IH A.5300@TK2MSFTN GP06.phx.gbl...
                          >
                          >
                          I had a problem similar to this, and I am still looking for the
                          solution.
                          >
                          I have an MDI form, instantiating a child form, calling the ShowDialog
                          method.
                          >
                          I works fine. Ithe problem is when the form is embbeded on a second
                          assembly, when it happens, it realy seems to start another thead,
                          becouse it don´t wait the window to close to continue the next step of
                          the procedure.
                          >
                          any idea?
                          >
                          Thanks and regards,
                          André Luiz Sobreiro
                          >
                          *** Sent via Developersdex http://www.developersdex.com ***

                          Comment

                          • Peter Duniho

                            #14
                            Re: does ShowDialog start new thread ?

                            On Mon, 23 Jun 2008 18:07:07 -0700, Jeff Winn <jwinn@nospam.c omwrote:
                            ShowDialog pauses the calling thread execution until the form has
                            closed, Show does not. ShowDialog would not be able to return the proper
                            dialog result if the thread continued processing. I don't see how
                            putting the class in another assembly would make any difference at all.
                            Important nit: ShowDialog() does not literally "pause the calling
                            thread". It's true that the method call ShowDialog() doesn't return until
                            the form is closed. But the thread itself continues to execute. It
                            simply spends its time in message pump loop handling the dialog, rather
                            than the top-level message pump loop initiated at the beginning of the
                            thread.

                            As for the previous poster's question: it's not impossible that you might
                            have some code that creates a new thread in which a dialog is shown.
                            However, without a concise-but-complete code sample that reliably
                            demonstrates your problem, it's not likely your question will be
                            answered. It's too vague as-is.

                            Pete

                            Comment

                            • Jeff Winn

                              #15
                              Re: does ShowDialog start new thread ?

                              Ah, guess I should have been a bit clearer on what I was thinking.

                              Thanks Pete

                              "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in message
                              news:op.uc9aqnz w8jd0ej@petes-computer.local. ..
                              On Mon, 23 Jun 2008 18:07:07 -0700, Jeff Winn <jwinn@nospam.c omwrote:
                              >
                              >ShowDialog pauses the calling thread execution until the form has
                              >closed, Show does not. ShowDialog would not be able to return the proper
                              >dialog result if the thread continued processing. I don't see how
                              >putting the class in another assembly would make any difference at all.
                              >
                              Important nit: ShowDialog() does not literally "pause the calling
                              thread". It's true that the method call ShowDialog() doesn't return until
                              the form is closed. But the thread itself continues to execute. It
                              simply spends its time in message pump loop handling the dialog, rather
                              than the top-level message pump loop initiated at the beginning of the
                              thread.
                              >
                              As for the previous poster's question: it's not impossible that you might
                              have some code that creates a new thread in which a dialog is shown.
                              However, without a concise-but-complete code sample that reliably
                              demonstrates your problem, it's not likely your question will be
                              answered. It's too vague as-is.
                              >
                              Pete

                              Comment

                              Working...