First of all, the code below seems to be working. It extracts jpeg images from a continuous byte stream and displays them in a pictureBox as they arrive if the encapsulating packet checksum is correct. The concern is intermittent GUI problems since the pictureBox is asynchronously updated by RxThread. Is the method used here OK or might this crash while showing it to the customer?
public FormMain()
{
InitializeComponent();
var t1 = new Thread(RxThread) { IsBackground = true };
t1.Start();
}
private void RxThread()
{
while (true)
{
... // validate incoming stream
var payload = new Byte[payloadSize];
... // copy jpeg image from stream to payload
pictureBox.Image = new Bitmap(new MemoryStream(payload));
}
}