I am new to multithreaded applications, and was having some problems
coordinating a few threads.
Here is the code I use:
ContextStorage cs = new ContextStorage(HttpContext.Current);
cs.setThread(runRetrieval);
runStart = new Thread(new ThreadStart(cs.RunStart));
runStart.Start();
Monitor.Enter(cs);
// wait until first of two threads completes and pulses all
Monitor.Wait(cs);
Monitor.Exit(cs);
// do same for second of the two threads
Monitor.Enter(cs);
Monitor.Wait(cs);
Monitor.Exit(cs);
// now do some other work
Basically I have this main thread, which starts and waits on a thread
runStart, which in turn starts and waits on another thread
runRetrieval. The way I communicate among these is that when the
runRetrieval completes, it pulses all waiting threads, including this
main one. runStart also gets pulsed, does some other work, and then
pulses again, which finally allows this main thread to continue
execution.
For some reason, however, even though it receives the first pulse, the
main thread hangs subsequently. Can anyone help me with this problem?
Thanks