473,549 Members | 2,670 Online
Bytes | Software Development & Data Engineering Community
+ 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 1975
Stirling <St******@discu ssions.microsof t.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
"interrupte d" with an event.

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

--
Jon Skeet - <sk***@pobox.co m>
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******@discu ssions.microsof t.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
"interrupte d" with an event.

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

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

Nov 16 '05 #3
Stirling <St******@discu ssions.microsof t.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.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
"Stirling" <St******@discu ssions.microsof t.com> wrote in message
news:60******** *************** ***********@mic rosoft.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
6000
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 localtime_r and asctime_r where I was using localtime and asctime. But I didn't find any correspondent _r function to "time".Also, I found that...
5
2592
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 be interrupted to handle an incoming event (and the flow of execution subsequently diverted to the respective event handler). My question is at...
1
1775
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, sinks events from outside sources. I realize the worker thread will be interrupted to handle an incoming event (and the flow of execution...
2
1846
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 thread, so that capture of data can continue if the UI is blocked with a modal dialg, for example. I would like each thread to be able to pass any FTP...
22
4068
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 (OS/compiler)? In my Windows applications, I use synchronization objects like, mutex, semaphores etc. Is there anything similar in the Standard ANSI C++ or...
6
6854
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 ThreadStart(open)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); }
34
2753
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
2285
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
6963
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 population. Whenever I call the thread, I pass it a structure containing the table and a few other parameters. The table goes in as a reference,...
2
2187
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 giving an example to explicitly express my understanding which may be also wrong: So, let's have a string in a module like: st = 'IAmAstring' My...
0
7521
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7810
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6044
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5369
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3501
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3483
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1944
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 we have to send another system
0
764
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.