G
Guest
system.InvalidOperationException: the object is currently in use elsewhere...
has anyone experienced this error before? I am occasionally getting this
error. I can't figure out what could possibly cause it. When the prog runs
thru the loop, the error could be thrown anytime. Sometimes it doesn't at all.
Seems like it's telling me that the picturebox is in use at the same time
that it wants to be updated. But I timed it...
displayImg = new bitmap(.... ) takes a lot longer than
updateUI_picturebox(Picturebox1, displayImg). Updating the image should not
take much time at all. What happening.... ?
'*****************
private Delegate Sub updateUI_Picturebox_delegate(ByVal picbox As
PictureBox, ByVal imgToDisplay As Image)
private sub someSub()
for i as integer = 0 to 99 ' for example
displayImg = new bitmap(.... ) ' assign some image
updateUI_picturebox(Picturebox1, displayImg) ' display image on
picturebox
next i
end sub
'-------------------------
Private Sub updateUI_pictureBox(ByVal picbox As PictureBox, ByVal
imgToDisplay As Image)
Dim handler As New updateUI_Picturebox_delegate(AddressOf
updateUI_Picturebox_handler)
Dim args() As Object = {picbox, imgToDisplay}
Me.BeginInvoke(handler, args)
End Sub
'-------------------------
Private Sub updateUI_Picturebox_handler(ByVal picBox As PictureBox,
ByVal imgToDisplay As Image)
Try
picBox.Image = imgToDisplay ' this line throws the
exception......
Catch ex As Exception
MsgBox(ex.ToString) ' exception is caught here....
End Try
End Sub
has anyone experienced this error before? I am occasionally getting this
error. I can't figure out what could possibly cause it. When the prog runs
thru the loop, the error could be thrown anytime. Sometimes it doesn't at all.
Seems like it's telling me that the picturebox is in use at the same time
that it wants to be updated. But I timed it...
displayImg = new bitmap(.... ) takes a lot longer than
updateUI_picturebox(Picturebox1, displayImg). Updating the image should not
take much time at all. What happening.... ?
'*****************
private Delegate Sub updateUI_Picturebox_delegate(ByVal picbox As
PictureBox, ByVal imgToDisplay As Image)
private sub someSub()
for i as integer = 0 to 99 ' for example
displayImg = new bitmap(.... ) ' assign some image
updateUI_picturebox(Picturebox1, displayImg) ' display image on
picturebox
next i
end sub
'-------------------------
Private Sub updateUI_pictureBox(ByVal picbox As PictureBox, ByVal
imgToDisplay As Image)
Dim handler As New updateUI_Picturebox_delegate(AddressOf
updateUI_Picturebox_handler)
Dim args() As Object = {picbox, imgToDisplay}
Me.BeginInvoke(handler, args)
End Sub
'-------------------------
Private Sub updateUI_Picturebox_handler(ByVal picBox As PictureBox,
ByVal imgToDisplay As Image)
Try
picBox.Image = imgToDisplay ' this line throws the
exception......
Catch ex As Exception
MsgBox(ex.ToString) ' exception is caught here....
End Try
End Sub