Fill PictureBox for each pixel with BackgroundWorker

Ndunks

New member
Joined
May 25, 2011
Messages
2
Location
Purwokerto, Jawa Tengah, Indonesia, Indonesia
Programming Experience
1-3
Hey, I need Help, I write this code:

' This calling the BackgroundWorker
Private Sub Button1_Click() Handles Button1.Click
BW.RunWorkerAsync()
End Sub

Private Sub BW_DoWork() Handles BW.DoWork
For y = 0 To Bmp.Height - 1
For x = 0 To Bmp.Width - 1
Bmp.SetPixel(x, y, Color.Black)
Me.PictureBox.Image = Bmp
System.Threading.Thread.Sleep(5)
Next x
Next y
End Sub

I will fill the picturebox with black color, and i need to see the process. but, when i execute the process, i got this error message:
Object is currently in use elsewhere.

How to do it??? :confused::confused:
 
The whole point of the BackgroundWork is to do work in the background. Making a change to the UI, e.g. setting the Image property of a PictureBox, is inherently foreground work. You don't need to assign the same Image object to the Image property of the PictureBox every iteration of the loop anyway. Do it once, on the UI thread, before starting the BackgroundWorker.

That said, I'm not sure that making a change to an Image that is already displayed in the UI won't cause issues anyway.
 
Back
Top