473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

system.InvalidOperationException: the object is currently in use .

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

Aug 14 '06 #1
1 2119
I found that the exception was thrown because the imgToDisplay was accessed
at the same time the picBox.image was going to be updated.

So I did a work-around, as follows....
( I don't think this is the best solution, so I do NOT recommend this
solution )

Private Sub updateUI_Picturebox_handler(ByVal picBox As PictureBox,
ByVal imgToDisplay As Image)

Do

Try
picBox.Image = imgToDisplay
Exit Do
Catch es as system.invalidOperationException
GoTo continueWithLoop
Catch ex As Exception
MsgBox(ex.ToString) ' other exception is caught here
Exit Do
End Try
continueWithLoop:

Loop

End Sub

Aug 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: David Conorozzo | last post by:
I am able to create new sources using CreateEventSource. I can call GetEventLogs, I can delete sources, I can see if sources exist BUT, as soon as I try a "WriteEntry", I get an exception: ...
1
by: Marc | last post by:
Hi! I'm working with a C# client that calls a php web service. I've created a wrapper to call the service using .NET wsdl tool (adding a web reference). The call to the server works fine, it...
5
by: Stacey Levine | last post by:
I have a webservice that I wanted to return an ArrayList..Well the service compiles and runs when I have the output defined as ArrayList, but the WSDL defines the output as an Object so I was...
0
by: John.Luckowsky | last post by:
Hello all, I've moved my old ASP1.1 with WSE2.0 SP3 to ASP2.0 and have found strange error which raises spontaneously. Here is the stack trace: System.InvalidOperationException Message: The...
4
by: Jos Lavrijsen | last post by:
When i try to re-use brushes or pens over multiple threads, i often get an InvalidOperationException with the message 'object is currently in use elsewhere'. I also tried this by re-using fonts...
0
by: banduraj | last post by:
I get an System.InvalidOperationException when trying to Serialize a struct that has a type refrenced from another library. The exception is: System.InvalidOperationException was unhandled...
0
by: nicomp | last post by:
I created a Web Service: I imported System.Data.SqlClient so I could access SQL server tables programmatically. The web service builds and deploys with no problems. When I try to add the...
3
by: Joseph Geretz | last post by:
System.InvalidOperationException: WebServiceBindingAttribute is required on proxy classes. My environment: Visual Studio 2005, targeting FX 2.0; I've developed a Web Service which uses DIME to...
4
by: yogarajan | last post by:
hi i had developed pop3 Account mail view in my web page but i got error in (System.NullReference Exception: Object reference not set) NetStrm.Write(szData, 0, szData.Length); - this line ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.