473,473 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do threads get entered in to?

So there are various ways to enter a thread. Example:

- Button click
- Event from delegate call back.
- etc...

In fact, I suppose all entry points are from some form of an event.

Questions:

- When I click a button, does it it get blocked till the last button
click is done? If so why?

- What about other events that I could get such as from MSMQ letting me
know a message has arrived? Or what about if I set up a call back
delegate for a web service to call me back on?

- Do these events call into my thread even if my thread is busy? If
not, how can I get them to call into my thread if my thread is busy?

Thanks!
Coder :)

Jan 20 '06 #1
5 1035
Me
Mmmm...Might be a little off or corn-fused.

Your WinForm application has one thread that is running all the time. When
you click on a button an event is raised in that one thread and it executes
your button code.

Below is a very simple example of what is happening in this thread.

while(true)
{
if(PeekMessage() == true)
then ProcessMessage()
}

PeekMessage() checks to see if there is a message waiting to be processed
and if there is then ProcessMessage() actually does the handing of it such
as calling your button code.

Now.. If you have a second,third,... thread that you created inside your
application then that is a different story. There is no "default" way that I
know of (there may be however?) to raise "enter" a thread in the way that an
event does. The thread is either running or it is not... If it is running
then you are probably in a loop (similar to the above one) doing whatever
your thread does.

Also, keep in mind that a thread is never really busy or not busy.. It is
always busy doing something otherwise it would be be in memory. Granted, it
may be performing a Sleep() or something simlar but it is still always
running/active/etc. in memory.

Hope this helps.

"Coder" <co*****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
So there are various ways to enter a thread. Example:

- Button click
- Event from delegate call back.
- etc...

In fact, I suppose all entry points are from some form of an event.

Questions:

- When I click a button, does it it get blocked till the last button
click is done? If so why?

- What about other events that I could get such as from MSMQ letting me
know a message has arrived? Or what about if I set up a call back
delegate for a web service to call me back on?

- Do these events call into my thread even if my thread is busy? If
not, how can I get them to call into my thread if my thread is busy?

Thanks!
Coder :)

Jan 20 '06 #2
Assuming we are talking about a WinForms application...

The underlying architecture of a Windows application (which should include a
WinForms application) is that it is "event-driven".

Everything the operating system wants to tell you about comes to you in the
form of a Windows message. This includes mouse movement, clicks, etc. They
arrive at your application in the form of a "windows message".

Your application, under the covers, is executing a loop, retrieving one
message at a time from the "message queue", and "dispatching" the message to
a processing function (a window proc).

Until the processing function returns, the next message cannot be processed.
This is why one button click must be processed before the next one. Windows
does not "jump in" to your application asynchronously to execute your event
handler. It just "seems" like that is what it is doing.

When you have an event that requires a substantial amount of processing, the
whole message loop grinds to a halt and the application becomes
non-responsive. For example, if your application was doing a large sort it
would not respond to button clicks until the sort completes (unless a
separate *thread* is explicitly started to perform the sort).

Ultimately one problem with most windows abstraction frameworks is you still
need to understand what is going on underneath the covers in order to use
the framework effectively.

Hope this helps.

"Coder" <co*****@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
So there are various ways to enter a thread. Example:

- Button click
- Event from delegate call back.
- etc...

In fact, I suppose all entry points are from some form of an event.

Questions:

- When I click a button, does it it get blocked till the last button
click is done? If so why?

- What about other events that I could get such as from MSMQ letting me
know a message has arrived? Or what about if I set up a call back
delegate for a web service to call me back on?

- Do these events call into my thread even if my thread is busy? If
not, how can I get them to call into my thread if my thread is busy?

Thanks!
Coder :)

Jan 20 '06 #3
Hi Me and or Kevin,

Thanks for your replies. I have a follow up question.

If button clicks, for instance, are being handled one at a time, then
what about other events I am subscribed to such as delegate call backs
from a web service or a message arrived event in MSMQ?

Jan 20 '06 #4
Coder <co*****@yahoo.com> wrote:
Hi Me and or Kevin,

Thanks for your replies. I have a follow up question.

If button clicks, for instance, are being handled one at a time, then
what about other events I am subscribed to such as delegate call backs
from a web service or a message arrived event in MSMQ?


Callbacks like that are usually executed in thread-pool threads, not in
the UI thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 20 '06 #5

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Coder <co*****@yahoo.com> wrote:
Hi Me and or Kevin,

Thanks for your replies. I have a follow up question.

If button clicks, for instance, are being handled one at a time, then
what about other events I am subscribed to such as delegate call backs
from a web service or a message arrived event in MSMQ?


Callbacks like that are usually executed in thread-pool threads, not in
the UI thread.


Which means that if they need to access the UI the should check the
InvokeRequired property on a Control/Form and if required exceute the action
using Invoke or BeginInvoke on a Control/Form - this will cause the delegate
you create to be pushed onto a queue and removed and executed by the UI
thread
Jan 20 '06 #6

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

Similar topics

3
by: Ronan Viernes | last post by:
Hi, I have created a python script (see below) to count the maximum number of threads per process (by starting new threads continuously until it breaks). ###### #testThread.py import...
0
by: Al Tobey | last post by:
I was building perl 5.8.2 on RedHat Enterprise Linux 3.0 (AS) today and noticed that it included in it's ccflags "-DTHREADS_HAVE_PIDS." I am building with -Dusethreads. With newer Linux...
10
by: [Yosi] | last post by:
I would like to know how threads behavior in .NET . When an application create 4 threads for example start all of them, the OS task manager will execute all 4 thread in deterministic order manes,...
1
by: andreas.baus | last post by:
Hi. I'm trying to figure out how to properly start and stop threads from a windows form. One thing I still have a problem with is how to make sure the spawned thread(s) are shut down when the...
10
by: Darian | last post by:
Is there a way to find all the thread names that are running in a project? For example, if I have 5 threads T1, T2, T3, T4, T5...and T2, T4, and T5 are running...I want to be able to know that...
9
by: bonk | last post by:
Does anyone have a simple example on how to prohibit that any thread other than the current thread modifies a certain object (a collection) while we are in a certain section of the code? In other...
2
by: Alexander Eisenhuth | last post by:
Hello pyqt users, i tried to use signal / slot across threads. With the following example I want to emit a signal when the thread loop is entered. The connected slot is never called. Why? ...
18
by: Jon Slaughter | last post by:
"Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than...
1
by: GarySharma | last post by:
Program should accept user input and do appropriate actions. But program hangs after creating 60 threads, that is after 60 transaction even if user submits input it doesn't take. I read that...
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
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...
1
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
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
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.