473,396 Members | 2,052 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,396 software developers and data experts.

UI thread Questions

Hi all,

I have a few questions here regarding UI thread.

(1) If I have two windows A and B, then I call
B.show() in A.
In this case, there will be only 1 UI thread which is
the window A UI thread regardless of whether window B
is shown as modal dialog or modeless window. This
window A UI thread will do all the processing needed
in window B if necessary.
Is this understanding correct?

(2) What if I do B.Invoke( new EventHandler
(showB) ) in A?
Will there be 2 separate UI threads?

Any suggestions or help is greatly appreciated.
Thank you in advance.

regards,
Sean
Nov 16 '05 #1
3 1592
> (1) If I have two windows A and B, then I call
B.show() in A.
In this case, there will be only 1 UI thread which is
the window A UI thread regardless of whether window B
is shown as modal dialog or modeless window. This
window A UI thread will do all the processing needed
in window B if necessary.
Is this understanding correct?
no. there is only one thread.

(2) What if I do B.Invoke( new EventHandler
(showB) ) in A?
Will there be 2 separate UI threads?


no. are you afraid you must synchronize? you don't have.

bye
rob
Nov 16 '05 #2
Hi,

"Sean" <an*******@discussions.microsoft.com> wrote in message
news:21****************************@phx.gbl...
Hi all,

I have a few questions here regarding UI thread.

(1) If I have two windows A and B, then I call
B.show() in A.
In this case, there will be only 1 UI thread which is
the window A UI thread regardless of whether window B
is shown as modal dialog or modeless window. This
window A UI thread will do all the processing needed
in window B if necessary.
Is this understanding correct?
You can create many windows' in one thread.
There is one message-loop inside Application.Run, Application.Run doesn't
return until your app is closed. So in application.Run there is a thight
loop which ask the os if there is a messages for any windows' that the
thread created, if there is it will lookup that window and call's it wndproc
passing the message, which in c# ussually ends in an eventhandler being
fired. The loop can't continue until the eventhandler is done.

A modal dialog is different.
When you call 'aForm.ShowDialog()' the call doesn't return until the modal
form is closed. So if you call this from an event handler, then the
main-message-loop can not continue. Therefore a modal dialog will create
it's own message-loop. The second message-loop behaves almost exactly the
same as the main one (it's in the same thread), but it will end when the
modal form is closed. This way it can also return the result to the caller
depending on which button was clicked.
Before showing the modal form WS_DISABLE window-style is applied to the
other top-level windows'.

(2) What if I do B.Invoke( new EventHandler
(showB) ) in A?
Will there be 2 separate UI threads?
To have two UI threads, start a thread and call Application.Run from the new
thread, this will create the message loop for that thread, so you'll end up
with 2 UI threads.
So
A UI thread is a thread with a message-loop, the message-loop fires the
events sequentially and synchronously.
Message-loops can be cascaded, but only the last one runs.
HTH,
greetings


Any suggestions or help is greatly appreciated.
Thank you in advance.

regards,
Sean

Nov 16 '05 #3
Hi Rob and BMermuys,

Thank you for both of your reply, especially BMermuys.
Your reply has deepened my understanding towards UI
thread :)
regards,
Sean
Nov 16 '05 #4

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

Similar topics

23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
2
by: Frank Rizzo | last post by:
I tried it on dotnet.vb, but got no answers. I'll try it here now. I have an app that listen to data on a certain resource. Data can come in on this resource any time, so I have to listen for it...
2
by: Frank Rizzo | last post by:
I have an app that listen to data on a certain resource.&nbsp; Data can come in on this resource any time, so I have to listen for it the entire time.&nbsp; I wanted to see if what I have is...
0
by: Frank Rizzo | last post by:
I have an app that listen to data on a certain resource. Data can come in on this resource any time, so I have to listen for it the entire time. I wanted to see if what I have is thread-safe and...
3
by: EnglishMan69 | last post by:
Hello All, I am using VB2005 Beta 2 in VS 2005 and am running into a small problem. I need to be able to add a picture box to the main form from within a thread. The program goes to a web...
4
by: iclinux | last post by:
hi there, I'm new to python, and have two questions: a. how to exit the whole process in a thread? b. when thread doing a infinite loops, how to terminate the process?: it seems that the...
27
by: Ritesh Raj Sarraf | last post by:
Hi, I have some basic doubts about thread. I have a list which has items in it which need to be downloaded from the internet. Let's say list is: list_items which has 100 items in it.
1
by: richard.hallgren | last post by:
Hi, I have some questions concerning thread pools. I've marked the questions by number in the text. First I'd like to know when which thread pools an application uses. I know ASP.NET uses the...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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,...
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.