A PictureBox control on a form won’t paint when using a Task to change the image (Example code attached)
private async void btnStartTask_Click(object sender, EventArgs e)
{
await Task.Run(() = > Task.FromResult(this.updateImage()));
}
public Task updateImage()Image image = imageList1.Images[ImageIndex].Image;
pictureBox1.Invoke((MethodInvoker)(() = >
{
//if you Break point or click on window and it renders… WeirD?
pictureBox1.Image = image;
pictureBox1.Invalidate();
}));
Thread.Sleep(750);
}
}
private void btnStartTimerUpdate_Click(object sender, EventArgs e)
{
tmrUpdatePic.Enabled = true;
}
int ImageIndex = 0;
private void tmrUpdatePic_Tick(object sender, EventArgs e)
{
if (++ImageIndex > imageList1.Images.Count – 1)
ImageIndex = 0;
pictureBox1.Image = imageList1.Images[ImageIndex].Image;
}
A task is a separate thread. Cannot update the browser without using a WebSocket connection and a push update. It’s not a Wisej issue.
Use Application.Update(). There is a section dedicated to this in the docs.
Please login first to submit.