I have an event handler that gets called anytime data is received on a serial port, once this event is called I process an individual byte of data until all data is processed.
My question is, how do I make sure that this IBSerialPort_DataReceived event handler doesn't get called again asynchronously while I am stilling processing bytes from the first time it was called, ie I want to guarantee the ProcessByte method is only ever executing on one thread at a time.
void IBSerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
while (BytesToRead > 0)
{
ProcessByte((byte)ReadByte());
}
}