I've got two picture boxes on the main form, one is a video stream from a webcam mounted on top of a robot, the other is some user feedback which is updated every now and again with a graph of what it thinks it can see (named map). Both pictures can be updated by any of the threads. How do I go about updating these pictures safely?
At the moment my Main Form has two methods with a delegate call in them like this:
public partial class MainForm : Form
{
public void videoImage(Image image)
{
this.VideoViewer.Image = image;
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate { videoImage(image); }));
}
}
public void mapImage(Image image)
{
this.VideoViewer.Image = image;
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate { mapImage(image); }));
}
}
}
The main robot thread has this in it:
public delegate void videoImageReady(System.Drawing.Image image);
public event videoImageReady videoImage;
and a third thread has
public delegate void mapImageReady(System.Drawing.Image image);
public event mapImageReady mapImage;
I'm not sure if this is the correct way to do it, or if there are better ways, this is just the way I found (but it doesn't work) I found this example and this example, but I didn't understand them completely, so I'm not entirely sure how to implement them.
Thanks in advance.