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

Home Posts Topics Members FAQ

Thread question

I have a main worker thread that spawns a child thread to do some listening.
What I would like to have happen is to have the child thread raise events in
the parent thread, and have the parent thread respond to those events.

Is it possible to have one thread raise events in another thread? So far I
have not been able to do so. Each thread seems to only be able to raise it's
own events.

Thanks in advance for any help.
Nov 16 '05 #1
4 1970
Stirling <St******@discussions.microsoft.com> wrote:
I have a main worker thread that spawns a child thread to do some listening.
What I would like to have happen is to have the child thread raise events in
the parent thread, and have the parent thread respond to those events.

Is it possible to have one thread raise events in another thread? So far I
have not been able to do so. Each thread seems to only be able to raise it's
own events.


Yup - raising events is effectively just calling methods.

You'll need your worker thread to be running some kind of message pump
or queue - it won't be able to do other things and suddenly be
"interrupted" with an event.

For an example of such a queue, see
http://www.pobox.com/~skeet/csharp/t...eadlocks.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Is there any kind of event in the parent thread that gets raised when a
message enters the queue? How does the thread know when another thread has
entered something into the queue?

"Jon Skeet [C# MVP]" wrote:
Stirling <St******@discussions.microsoft.com> wrote:
I have a main worker thread that spawns a child thread to do some listening.
What I would like to have happen is to have the child thread raise events in
the parent thread, and have the parent thread respond to those events.

Is it possible to have one thread raise events in another thread? So far I
have not been able to do so. Each thread seems to only be able to raise it's
own events.


Yup - raising events is effectively just calling methods.

You'll need your worker thread to be running some kind of message pump
or queue - it won't be able to do other things and suddenly be
"interrupted" with an event.

For an example of such a queue, see
http://www.pobox.com/~skeet/csharp/t...eadlocks.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
Stirling <St******@discussions.microsoft.com> wrote:
Is there any kind of event in the parent thread that gets raised when a
message enters the queue? How does the thread know when another thread has
entered something into the queue?


The way the example I mentioned is coded, the parent thread wakes up
from its call to Monitor.Wait, because there's a call to Monitor.Pulse
when a message enters the queue.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
"Stirling" <St******@discussions.microsoft.com> wrote in message
news:60**********************************@microsof t.com...
I have a main worker thread that spawns a child thread to do some listening. What I would like to have happen is to have the child thread raise events in the parent thread, and have the parent thread respond to those events.

Is it possible to have one thread raise events in another thread? So far I have not been able to do so. Each thread seems to only be able to raise it's own events.


Are you sure that it's necessary that the event be handled on the parent's
thread? It's probably OK to let the event be handed on the child thread.
You just have to watch out for UI control access and sync issues. It
depends on what you are really needing to do.

One other problem you will have with the queue technique is that the child
thread can pump those messages in pretty fast. The way I describe is
naturally throttled because the child thread can't raise another event until
the earlier event handler finishes. YMMV.

-- Alan

Nov 16 '05 #5

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

Similar topics

9
5994
by: rnn98 | last post by:
hi, my multithread application, running under solaris box, is crashing eventually. I tried to spot and substitute functions not "thread safe", but I guess my search wasn't good enough. I have put...
5
2587
by: Bill Davidson | last post by:
Hello All: I've got a question about synchronization requiremements in a C# worker thread procedure that, among other things, sinks events from outside sources. I realize the worker thread will...
1
1763
by: Bill Davidson | last post by:
(RESEND: I added a little more code to the sample for clarity) Hello All: I've got a question about synchronization requiremements in a C# worker thread procedure that, among other things,...
2
1829
by: James Lavery | last post by:
Hi everyone, We're developing an application to capture data from several serial ports, store in a database, and (optionally) forward on using FTP. Each serial port is being processed in a...
22
4060
by: Morpheus | last post by:
Hi, I have been coding in Windows for many years so have a mindset to it, so forgive any stupid questions. Is it possible to create a multithread application in C++ that is portable...
6
6840
by: Sergey Poberezovskiy | last post by:
I have the following code in C# that I have trouble converting to VB(2.0): private delegate void openDialog(); private void openWindowsDialog(openDialog open) { Thread thread = new Thread(new...
34
2749
by: Creativ | last post by:
Why does Thread class not support IDisposable? It's creating quite some problem. Namely, it can exhaust the resource and you have not control over it.
19
2275
by: Hapa | last post by:
Does only reading (never writing) of a variable need thread synchronisation? Thanks for help? PS. Anybody knows a Visual C++ news group?
9
6946
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
2
2176
by: k3xji | last post by:
Hi all, This will probably be a long question/short answer, sorry, but I have wandered net about the subject and really feel cannot find just enough information.I want to ask my question by...
0
6950
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7103
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
7140
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
6811
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
5403
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,...
1
4841
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...
0
4527
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3044
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
3038
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.