G
Guest
Hi,
I have to send several messages at the same time and wait for the replies,
so I use a thread for each message.
//Get all the data at the same time.
foreach(Thread thread in threads) thread.Start();
//Wait till all the data is retrieved.
foreach(Thread thread in threads) thread.Join();
And this works... sometimes :/
All the threads always start ok, so all the messages are sent out ok.
But the main thread doesn't always wait for all the threads to finish... The
main thread sometimes continues, even though I haven't received all my
replies.
Why is this?
The only thing I can come up with, is that it might be because of when i
spin, waiting for an answer.
while (!stream.DataAvailable ){}
Maybe if all the threads but one last one are finished, and the last one is
still waiting for an answer, then this last thread might go to sleep or
something, causing the main thread to continue?
Or is this not possible?
I have no clue at all on how to solve this.
I have to send several messages at the same time and wait for the replies,
so I use a thread for each message.
//Get all the data at the same time.
foreach(Thread thread in threads) thread.Start();
//Wait till all the data is retrieved.
foreach(Thread thread in threads) thread.Join();
And this works... sometimes :/
All the threads always start ok, so all the messages are sent out ok.
But the main thread doesn't always wait for all the threads to finish... The
main thread sometimes continues, even though I haven't received all my
replies.
Why is this?
The only thing I can come up with, is that it might be because of when i
spin, waiting for an answer.
while (!stream.DataAvailable ){}
Maybe if all the threads but one last one are finished, and the last one is
still waiting for an answer, then this last thread might go to sleep or
something, causing the main thread to continue?
Or is this not possible?
I have no clue at all on how to solve this.