C
Charles Law
I know I have brought this one up before, but I didn't get an answer last
time, so hopefully I will have better luck this time.
I send data out of a serial port on my main thread. I wait for a response on
a background thread. While my main thread is waiting (only 100ms) it sits in
a loop calling DoEvents and testing a flag.
The background thread looks at the incoming data, and when it recognises
something it sets a flag.
Meanwhile, the main thread sees that the flag has been set and processes the
response. All well and good.
But if I replace the call to DoEvents with Thread.Sleep(10) it doesn't work
anymore. The background thread never gets a sniff at the data. Why would
that be? I thought the point of multi-threading was that you didn't need to
'yield' to allow another thread to get processing time.
Incidentally, please feel free to criticise the overall technique I have
described. I'm not totally happy with it myself, so any suggestions are
welcome.
TIA
Charles
time, so hopefully I will have better luck this time.
I send data out of a serial port on my main thread. I wait for a response on
a background thread. While my main thread is waiting (only 100ms) it sits in
a loop calling DoEvents and testing a flag.
The background thread looks at the incoming data, and when it recognises
something it sets a flag.
Meanwhile, the main thread sees that the flag has been set and processes the
response. All well and good.
But if I replace the call to DoEvents with Thread.Sleep(10) it doesn't work
anymore. The background thread never gets a sniff at the data. Why would
that be? I thought the point of multi-threading was that you didn't need to
'yield' to allow another thread to get processing time.
Incidentally, please feel free to criticise the overall technique I have
described. I'm not totally happy with it myself, so any suggestions are
welcome.
TIA
Charles