473,405 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

does ShowDialog start new thread ?

Hi,

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

Thx
Jun 27 '08 #1
14 6754
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***@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Jun 27 '08 #2
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...@vkarlsen.nohttp://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
I was under a notion that Show and ShowDialog would executeon a
different thread. Seems interesting..Thanks Lasse.
Jun 27 '08 #3
On 5月5æ—¥, 下åˆ7æ—¶29分, "Aneesh Pulukkul [http://dotnet-
revolutions.blogspot.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...@vkarlsen.nohttp://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3

I was under a notion that Show and ShowDialog would executeon a
different thread. Seems interesting..Thanks Lasse.
Every window should have a thread to process messages, right?
Jun 27 '08 #4
"Aneesh Pulukkul [http://dotnet-revolutions.blogspot.com]"
<an******@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.
Jun 27 '08 #5
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" <fi******************@CL4.orgwrote in message
news:fp******************************@bt.com...
"Aneesh Pulukkul [http://dotnet-revolutions.blogspot.com]"
<an******@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.

Jun 27 '08 #6
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.
Jun 27 '08 #7
On Mon, 05 May 2008 05:19:41 -0700, Robin <zo********@gmail.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.
Jun 27 '08 #8
On Mon, 05 May 2008 07:27:21 -0700, shark <ma**@poczta.onet.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
Jun 27 '08 #9
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" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Mon, 05 May 2008 05:19:41 -0700, Robin <zo********@gmail.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.
Jun 27 '08 #10
On Mon, 05 May 2008 23:04:11 -0700, shark <ma**@poczta.onet.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
Jun 27 '08 #11


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 ***
Jun 27 '08 #12
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" <so******@yahoo.comwrote in message
news:OL**************@TK2MSFTNGP06.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 ***
Jun 27 '08 #13
On Mon, 23 Jun 2008 18:07:07 -0700, Jeff Winn <jw***@nospam.comwrote:
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
Jun 27 '08 #14
Ah, guess I should have been a bit clearer on what I was thinking.

Thanks Pete

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Mon, 23 Jun 2008 18:07:07 -0700, Jeff Winn <jw***@nospam.comwrote:
>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
Jun 27 '08 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Isaac Rajan | last post by:
Hello, I have installed MSDE2000A on a standalone PC with Win ME O/s. The PC was earlier used on a Lan and has a Lan card. I could install a named instance of the server successfully but the...
2
by: Dayne | last post by:
Does an asychronous thread (.beginInvoke) die when the method call ends? DT
75
by: Beni | last post by:
I have been programming in C for about a year now. It sounds silly, but I never took the time to question why a C(or C++ or Java) program execution begins only at the main(). Is it a convention or...
1
by: Suman | last post by:
We are facing a problem with a Service we developed. It does not start after a re-boot. We can Start/Stop the service from the interfacing Application and the Services Control Panel all day long....
1
by: aberry | last post by:
I have text file which contain Unicode data (say inp.txt) I read file using following code:- import codecs infile = codecs.open('C:\\tdata\\inp.txt','r','utf-16',errors='ignore') data =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.