|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
.NET thread communicationHi,
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 > I have a parent thread that starts a child thread. After the child thread I suggest a ManualResetEvent (mre). Create it in the parent thread in > 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.. 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. "AMercer" wrote: This sounds like exactly what I needed. Thanks man.> I suggest a ManualResetEvent (mre). regards, martin 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: Show quote > 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 |
|||||||||||||||||||||||