473,224 Members | 1,976 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,224 software developers and data experts.

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 1028
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.