thread question
-
I writing an windows app in C# that receives data via serial port. I have a thread dedicated to reading from the serial port and when it has a full packet, it makes a call to the main form.
CallBackUpdate callBack = new CallBackUpdate(updateState); Invoke(callBack, new object[] { newPacket });
So it passes the newPacket to a method called updateState. Lets say this happens: (Although I don't think it will) 1.Receive one packet and is sent to main form for processing. 2.Receive another packet and send it to main form before packet from 1 is done processing. Question/Concern Will the main form process the first packet completely before it processes the second? or Do I have to add some blocking to the serial thread so that it doesn't send a packet for processing when another is being processed. -
I writing an windows app in C# that receives data via serial port. I have a thread dedicated to reading from the serial port and when it has a full packet, it makes a call to the main form.
CallBackUpdate callBack = new CallBackUpdate(updateState); Invoke(callBack, new object[] { newPacket });
So it passes the newPacket to a method called updateState. Lets say this happens: (Although I don't think it will) 1.Receive one packet and is sent to main form for processing. 2.Receive another packet and send it to main form before packet from 1 is done processing. Question/Concern Will the main form process the first packet completely before it processes the second? or Do I have to add some blocking to the serial thread so that it doesn't send a packet for processing when another is being processed.dino2094 wrote:
Invoke(callBack, new object[] { newPacket });
Careful here. This will block until the Form invokes the delegate and it completes. Your serial port thread won't be able to do anything else. Perhaps try BeginInvoke instead.
dino2094 wrote:
Will the main form process the first packet completely before it processes the second?
Yes.
dino2094 wrote:
Do I have to add some blocking to the serial thread so that it doesn't send a packet for processing when another is being processed.
Well, you get that for free by using Invoke rather than BeginInvoke. But I'm betting you'd probably want to use BeginInvoke instead.