473,387 Members | 1,504 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,387 software developers and data experts.

InvalidOperationException object is currently in use elsewhere - red cross

Hello

I have a C# desktop application in which one thread that I create continously gets an image from a

source(it's a digital camera actually) and puts it on a panel(panel.Image = img) in the GUI(which

must be another thread as it is the code-behind of a control.

The application works but on some machines I get the following error at random time

intervals(unpredictable)

Expand|Select|Wrap|Line Numbers
  1.  
  2. ************** Exception Text **************
  3. System.InvalidOperationException: The object is currently in use elsewhere.
  4.  
  5.  

Then the panel turns into a red cross, red X - i think this is the invalid picture icon that is

editable from the properties. The application keeps working but the panel is never updated

From what I can tell this error comes from the control's onpaint event where I draw something else

on the picture

I tried using a lock there but no luck :(

The way I call the function that puts the image on the panel is as follows:

Expand|Select|Wrap|Line Numbers
  1. if (this.ReceivedFrame != null)
  2.                 {
  3.                     Delegate[] clients = this.ReceivedFrame.GetInvocationList();
  4.                     foreach (Delegate del in clients)
  5.                     {
  6.                         try
  7.                         {
  8.                             del.DynamicInvoke(new object[] { this, new StreamEventArgs(frame) });
  9.                         }
  10.                         catch { }
  11.                     }
  12.                 }
  13.  

this is the delegate:

Expand|Select|Wrap|Line Numbers
  1. public delegate void ReceivedFrameEventHandler(object sender, StreamEventArgs e);
  2.         public event ReceivedFrameEventHandler ReceivedFrame;
  3.  

and this is how the function inside the control code-behind registers to it:

Expand|Select|Wrap|Line Numbers
  1. Camera.ReceivedFrame += new Camera.ReceivedFrameEventHandler(camera_ReceivedFrame);
  2.  

I also tried
Expand|Select|Wrap|Line Numbers
  1. del.Method.Invoke(del.Target, new object[] { this, new StreamEventArgs(b) });
  2.  
instead of
Expand|Select|Wrap|Line Numbers
  1. del.DynamicInvoke(new object[] { this, new StreamEventArgs(frame) });
  2.  

but no luck


Does anyone know how I could fix this error or at least catch the error somehow and make the thread put the images on the panel once again?

Can anyone help please? I am really stuck
Thank you in advance
Jun 29 '09 #1
0 2308

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Netocrat | last post by:
Any comments on the correctness of the statements 1, 2a, 2b, 3 and 4 in the code below? If they are correct, then the definition of an object as well as that of an lvalue is broken in C99 by the...
4
by: 6tc1 | last post by:
Hi all, I have just finished debugging a windows application and have solved the problem - however, I want to be sure that I understand the problem before I move on. Before I detail the problem,...
1
by: Hadar | last post by:
Hi, I'm getting "object is currently in use elsewhere" when I use System.Drawing.Graphics.MesureString. This is what I do: My controls use a utility class the helps it to mesure strings. To...
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...
8
by: Sharon | last post by:
I have a DataGrid control on a Form. The data of the control is added by another application by Remoting. It means that a worker thread is invoking a UI thread. Therefore I used a delegate in the...
4
by: JJ | last post by:
When I run my form prog, if I maximise, then minimise (i..i. force the GUI to redraw) I get the following error: "The object is currently in use elsewhere" At this line: ...
4
by: Mau Kae Horng | last post by:
Hello, I have a C# Windows Forms application for machine. Due to some unknown reasons, the application face problems with unexpected exceptions happening, resulting in two red lines forming a...
1
by: chad | last post by:
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...
4
by: =?Utf-8?B?Qm9uaQ==?= | last post by:
Hi, I got this problem. I'm implementing a pluggable winform program. My plugins are usercontrol and I load them in my program through a interface. Now if I close my application an error occurs:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.