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

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 1969
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
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.