Object in use else where.

krsh24

Active member
Joined
Sep 16, 2006
Messages
25
Programming Experience
3-5
Hi,

I am facing this issue for a long time, not able to fix it.

I have an emulator that displays exactly what is displayed on a signature pad. This emulator is drawn using pen and brushes on a picture box.

I have a main event handler that receives all events from the pad and this event handler requests the emulator to be drawn. There are possiblities where events are fired continiously and requesting emulator to be re drawn.

I get this exception with a BIG RED X on the emulator screen saying

The object is currently in use elsewhere. at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
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.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at mdlMain.Main(String[] CmdArgs)


I have implemented a mutex in the method that redraws the emulator using pen and brush. I have also tried using a thread safe picture box by implementing a mutex in the OnPaint event of the threadsafe picture box. There are no steps to recreate this issue. This happens randomly :(

Your help would be really appreciated.

Thanks
Krsh
 
Back
Top