Paint Event fires once and then only fires from mouse but not invalidate/refresh?

0
0

A PictureBox control on a form won’t paint when using a Task to change the image (Example code attached)

UNLESS Breakpoint in code or the form is clicked ? ? ?
Invalidate, Refresh, Tasks etc just wont fire via ui updates, why ? Trying everything… Wired up  paint event in case of lazy loading…
Currently Digging through Wj Double buffer etc and getting into Js events to see why mouse fires paint but code won’t play nice…
private async void btnStartTask_Click(object sender, EventArgs e)
{
await Task.Run(() = > Task.FromResult(this.updateImage()));
}
public Task updateImage()
{
while (true)
{
if (++ImageIndex & gt; imageList1.Images.Count – 1)
ImageIndex = 0;

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);

}
}

Funny thing is this Code works when I use a Timer?

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;
}

 Got to be something simple.. but what is it?
  • You must to post comments
0
0

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.

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.