"Red Cross" - The object is currently in use elsewhere

G

Guest

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 red cross across a certain
control (the entire form, labels and so on). I get the following message in
MessageBox.



See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.InvalidOperationException: The object is currently in use elsewhere.
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at
System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer
buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Label.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)




The machine is used to handle Microchip Test. When running in production, it
will update the output quantity on the Forms. When the "Red Cross" appears,
the application will hang but machine still keep running. All the data that
generate after that will be lost. This issue is very serious. All my customer
complaining on this issue.


Anyone has the solution? Please reply me as soon as possible. Thanks.
 
S

Stoitcho Goutsev \(100\)

Mau Kae Horng,

So you use different threads to draw on the control/form at the same time?
 
B

Bhagat Gurtu

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 red cross across a certain
control (the entire form, labels and so on). I get the following message in
MessageBox.

You have Red Cross virus.
 
G

Guest

Actually, I am using multithreading in the application. The threads will set
the Event to let the application to do the data updates on the form. In other
words, the form will updates in every 100ms depending on the event set by
other threads.

Beside, all the control I am using is User Control. I inherit the
System.Windows.Forms.Control to create my own control. I also override
On_Paint() function to draw my own style for the control. Will this affected?
 
S

Stoitcho Goutsev \(100\)

Mau Kae Horng,

All the updates thad you do to the UI has to be done by the UI thread (the
thread that runs the message pump and has created the controls). If you try
to update the UI from a working thread many bad things can happen including
the error that you get. Marshaling the call is done via Control.Invoke or
Control.BeginInvoke methods.

This question has been asked milons of times; just google for Control.Invoke
and Control.InvokeRequired to find out how to do it.


--
HTH
Stoitcho Goutsev (100)

Mau Kae Horng said:
Actually, I am using multithreading in the application. The threads will
set
the Event to let the application to do the data updates on the form. In
other
words, the form will updates in every 100ms depending on the event set by
other threads.

Beside, all the control I am using is User Control. I inherit the
System.Windows.Forms.Control to create my own control. I also override
On_Paint() function to draw my own style for the control. Will this
affected?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top