Object is currently in use elsewhere!
-
Hi has anyone have any idea about the following error?
Message = Object is currently in use elsewhere. , StackTrace = at System.Drawing.Image.get_Width() at System.Drawing.Image.get_Size() at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.CommonLayout() at System.Windows.Forms.ButtonInternal.ButtonFlatAdapter.PaintFlatLayout(PaintEventArgs e, Boolean up, Boolean check, Int32 borderSize) at System.Windows.Forms.ButtonInternal.ButtonFlatAdapter.PaintUp(PaintEventArgs e, CheckState state) at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.Paint(PaintEventArgs pevent) at System.Windows.Forms.ButtonBase.OnPaint(PaintEventArgs pevent) at EES.ATE.TouchScreenControls.TouchScreenButton.OnPaint(PaintEventArgs pevent) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam
Actually I am updating a GUI's Button image in Backgroundworker class, I didn't use Invokerequired property. I suspect that would be the cause of this error. But this error has been captured Application_ThreadException event. Any idea when this error will occur? -
Hi has anyone have any idea about the following error?
Message = Object is currently in use elsewhere. , StackTrace = at System.Drawing.Image.get_Width() at System.Drawing.Image.get_Size() at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.CommonLayout() at System.Windows.Forms.ButtonInternal.ButtonFlatAdapter.PaintFlatLayout(PaintEventArgs e, Boolean up, Boolean check, Int32 borderSize) at System.Windows.Forms.ButtonInternal.ButtonFlatAdapter.PaintUp(PaintEventArgs e, CheckState state) at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.Paint(PaintEventArgs pevent) at System.Windows.Forms.ButtonBase.OnPaint(PaintEventArgs pevent) at EES.ATE.TouchScreenControls.TouchScreenButton.OnPaint(PaintEventArgs pevent) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam
Actually I am updating a GUI's Button image in Backgroundworker class, I didn't use Invokerequired property. I suspect that would be the cause of this error. But this error has been captured Application_ThreadException event. Any idea when this error will occur?A background thread should never interact with the UI directly. Instead it should tell the main thread to do it.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
A background thread should never interact with the UI directly. Instead it should tell the main thread to do it.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Thats correct. But i read this BackgroundWorker class will not have any cross-threading issues. Is it right? also tell me is this error comes because of Cross-threading invalid operation?
engsrini wrote:
But i read this BackgroundWorker class will not have any cross-threading issues. Is it right?
You still have to synchronise the threads regardless of how the thread is wrapped up.
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
Thats correct. But i read this BackgroundWorker class will not have any cross-threading issues. Is it right? also tell me is this error comes because of Cross-threading invalid operation?
The
BackgroundWorker
will not allow any cross-thread operations and will throw an exception if you try to do so. You still need to have a basic understanding of how threading works even when using theBackgroundWorker
. If you are trying to change the button image as the result of either progress or completion, you need to do so using either the ProgressChanged or RunWorkerCompleted events. (If you use ProgressChanged, make sure to set theWorkerReportsProgress
property to true. See http://msdn2.microsoft.com/en-us/library/system.componentmodel.backgroundworker(vs.80).aspx[^] for more details.----------------------------- In just two days, tomorrow will be yesterday.