PC Review


Reply
Thread Tools Rate Thread

.NET thread communication

 
 
=?Utf-8?B?bWFydGlu?=
Guest
Posts: n/a
 
      5th Apr 2006
Hi,

I have a parent thread that starts a child thread. After the child thread
has been started I want the parent thread to wait until the child thread has
reached to a specific point in it's work. What .NET primitive should I use
for this "waiting until another thread reaches a specific point" mechanism? I
don't want to use some ugly hack which will spin the CPU at 100% or such..


regards,
martin
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QU1lcmNlcg==?=
Guest
Posts: n/a
 
      5th Apr 2006
> I have a parent thread that starts a child thread. After the child thread
> has been started I want the parent thread to wait until the child thread has
> reached to a specific point in it's work. What .NET primitive should I use
> for this "waiting until another thread reaches a specific point" mechanism? I
> don't want to use some ugly hack which will spin the CPU at 100% or such..


I suggest a ManualResetEvent (mre). Create it in the parent thread in
blocking state. Launch the new thread and wait on the mre (call
mre.WaitOne). Have the child thread signal the mre at whatever point you
want.

The only difficulty is that the mre needs to be accessible to both threads.
I think in .net 2005 the parent can pass the mre to the child, but I'm not at
2005 yet, so I don't know. If you are .net 2003 or earlier, you will have to
worry this problem. The easy way out is a shared variable/module, and if
there are no broader multi-threading issues, that will work.
 
Reply With Quote
 
=?Utf-8?B?bWFydGlu?=
Guest
Posts: n/a
 
      5th Apr 2006
"AMercer" wrote:
> I suggest a ManualResetEvent (mre).


This sounds like exactly what I needed. Thanks man.


regards,
martin
 
Reply With Quote
 
joey.powell@topscene.com
Guest
Posts: n/a
 
      5th Apr 2006
I did this once with delegates and AsyncCallBack/Result. Might be worth
looking into. I had no idea what I was doing at the time, but I got it
to work!

JP

martin wrote:
> Hi,
>
> I have a parent thread that starts a child thread. After the child thread
> has been started I want the parent thread to wait until the child thread has
> reached to a specific point in it's work. What .NET primitive should I use
> for this "waiting until another thread reaches a specific point" mechanism? I
> don't want to use some ugly hack which will spin the CPU at 100% or such..
>
>
> regards,
> martin


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
thread communication Ronny Microsoft C# .NET 9 16th Oct 2008 11:46 PM
Thread Communication in C# Jayme Pechan Microsoft C# .NET 8 16th Jan 2006 11:55 PM
Thread communication Maurice Microsoft Dot NET 1 23rd Nov 2004 03:03 PM
communication in different thread? Jet Leung Microsoft C# .NET 1 30th Aug 2004 09:06 PM
Inter-thread communication to pass a job to another thread James Lavery Microsoft VB .NET 2 26th May 2004 11:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:49 PM.