InvalidOperationException object is currently in use elsewhere - red cross

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • para15000
    New Member
    • Jun 2009
    • 2

    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.Ima ge = 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(unpre dictable)

    Code:
    ************** Exception Text **************
    System.InvalidOperationException: The object is currently in use elsewhere.

    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:

    Code:
    if (this.ReceivedFrame != null)
    				{
                        Delegate[] clients = this.ReceivedFrame.GetInvocationList();
                        foreach (Delegate del in clients)
                        {
                            try
                            {
                                del.DynamicInvoke(new object[] { this, new StreamEventArgs(frame) });
                            }
                            catch { }
                        }
                    }

    this is the delegate:

    Code:
    public delegate void ReceivedFrameEventHandler(object sender, StreamEventArgs e);
    		public event ReceivedFrameEventHandler ReceivedFrame;

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

    Code:
    Camera.ReceivedFrame += new Camera.ReceivedFrameEventHandler(camera_ReceivedFrame);

    I also tried
    Code:
    del.Method.Invoke(del.Target, new object[] { this, new StreamEventArgs(b) });
    instead of
    Code:
    del.DynamicInvoke(new object[] { this, new StreamEventArgs(frame) });

    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
Working...