473,883 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

does ShowDialog start new thread ?

Hi,

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

Thx
Jun 27 '08
14 6816
On Mon, 05 May 2008 23:04:11 -0700, shark <ma**@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
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******** ******@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 ***
Jun 27 '08 #13
On Mon, 23 Jun 2008 18:07:07 -0700, Jeff Winn <jw***@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
Jun 27 '08 #14
Ah, guess I should have been a bit clearer on what I was thinking.

Thanks Pete

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

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

Similar topics

3
5986
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 server does not start when I attempt to start it using the service manager. Could you tell me how this could be solved? Thanks in advance.
2
1380
by: Dayne | last post by:
Does an asychronous thread (.beginInvoke) die when the method call ends? DT
75
9925
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 is there some deeper underlying reason?
1
4356
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. But it does not start after a reboot. Details We have implemented the Service using CAtlServiceModuleT (ATL 7.0). For initialization and un-initialization, we have overridden the PreMessageLoop and the PostMessageLoop. In the initialization...
1
35098
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 = infile.readlines() If I run above code ... it throws following error :-
0
9948
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11164
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10767
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10864
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9588
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7980
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6008
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4230
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.