I have a worker thread in my application that is responsible for three different things. Requests for two of the jobs turn up in Queues that I have written, the other job is
You can use the async methods of the NetworkStream and set a ManualResetEvent in the EndReceive method.
// ...
netStream.BeginRead(buffer, offset, callback, state);
// ...
inside the callback method
netStream.EndRead(ar);
netStreamManualResetEvent.Set();
then your code
while (notDone)
{
WaitHandle.WaitAny(new WaitHandle[] { queue1.HasData, queue2.HasData, netStreamManualResetEvent} );
// ...
if (netStream.DataAvailable)
{
// make the buffer from the AsyncState in the callback method available here
// process buffer
}
}