.NET thread communication

G

Guest

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
 
G

Guest

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.
 
J

joey.powell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top