To safely update a PictureBox control on a Form from a thread other than the thread it was created on in WinForms using C#, you can make use of the Control.Invoke method. Here’s an example of how you can achieve this:

  1. Define a delegate and an event in the Form class that will handle the PictureBox update:
public delegate void UpdatePictureBoxDelegate(Image image);
public event UpdatePictureBoxDelegate UpdatePictureBoxEvent;

In the Form’s constructor or Load event handler, subscribe to the UpdatePictureBoxEvent and handle the actual PictureBox update:

public Form2()
{
    InitializeComponent();
    UpdatePictureBoxEvent += UpdatePictureBox;
}

private void UpdatePictureBox(Image image)
{
    pictureBox1.Image = image;
}

From your other thread, when you want to update the PictureBox, use Control.Invoke to safely execute the update on the UI thread:

private void UpdatePictureBoxFromThread(Image image)
{
    if (pictureBox1.InvokeRequired)
    {
        pictureBox1.Invoke(new UpdatePictureBoxDelegate(UpdatePictureBoxFromThread), image);
    }
    else
    {
        UpdatePictureBoxEvent?.Invoke(image);
    }
}

In the above code, the UpdatePictureBoxFromThread method checks if invoking is required (i.e., the current thread is different from the UI thread). If it is, it uses Control.Invoke to execute the update method on the UI thread. If not, it directly invokes the UpdatePictureBoxEvent to update the PictureBox.

You can then call the UpdatePictureBoxFromThread method from your separate thread, passing in the updated image as a parameter. The PictureBox update will be safely executed on the UI thread.

Remember to handle any exception that might occur during the PictureBox update to avoid crashes.