By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,028 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,028 IT Pros & Developers. It's quick & easy.

Race Condition with GDI+

P: n/a
I'm writing a program that deals extensively with the printer. For the most
part my application runs fine, but occasionally I run into some Exceptions.
The most common exceptions I run into are NullReferenceException and
InvalidOperationException : The object is currently in use elsewhere.
Unfortunately this appears to be a race condition. These exceptions appear
to ocurr while disposing GDI+ objects, the Graphics object seems to be the
biggest culprit. Unfortunately all of these Exceptions ocurr in
System.Drawing.dll, as a result no source code is avaialable. These
Exceptions always ocurr while my program is printing. I would provide the
source code for this, but these Exceptions are blown during various portions
of my printing algorithm (approximately 3,000 lines), and exposing that would
put my job in jeapordy. I'm hoping that someone out there is familiar enough
with GDI+ to know why these Exceptions are being thrown. Any help would be
appreciated.

Here is the stack trace for my exceptions:

************** Exception Text **************
System.InvalidOperationException: The object is currently in use elsewhere.
at System.Drawing.Graphics.Dispose(Boolean disposing)
at System.Drawing.Graphics.Dispose()
at System.Drawing.Printing.PrintController.PrintLoop( PrintDocument
document)
at System.Drawing.Printing.PrintController.Print(Prin tDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Erudite.CheckManagerSystem.CheckRunPrinter.BeginPr inting()
at
CheckManager.ChequePrinting.New_GUI.PrintForm.Prin tingDataLoaded(CheckRun
checkRun, DataLoadedEventArgs args)
at Erudite.CheckManagerSystem.CheckRun.OnDataLoaded(C HECK_HEADERDataTable
checkHeaders)
at Erudite.CheckManagerSystem.CheckRun.LoadData(Check Type checkType)
at
Erudite.CheckManagerSystem.CheckRun.LoadHeaderData (CheckRunEventHandler
beginLoadingDataCallback, CheckRunDataLoadedHandler dataLoadedCallback)
at CheckManager.ChequePrinting.New_GUI.PrintForm.ubtn _Print_Click(Object
sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButtonBase.OnClick(Even tArgs e)
at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseE ventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
************** Exception Text **************
System.ArgumentException: Invalid parameter used.
at System.Drawing.Image.get_FrameDimensionsList()
at System.Drawing.ImageAnimator.CanAnimate(Image image)
at System.Drawing.ImageInfo..ctor(Image image)
at System.Drawing.ImageAnimator.Animate(Image image, EventHandler
onFrameChangedHandler)
at System.Windows.Forms.PictureBox.Animate(Boolean animate)
at System.Windows.Forms.PictureBox.Animate()
at System.Windows.Forms.PictureBox.OnVisibleChanged(E ventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChange d(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(Even tArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleCh anged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventAr gs e)
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

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

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an
object.
at System.Drawing.SafeNativeMethods.GdipDrawImageRect RectI(HandleRef
graphics, HandleRef image, Int32 dstx, Int32 dsty, Int32 dstwidth, Int32
dstheight, Int32 srcx, Int32 srcy, Int32 srcwidth, Int32 srcheight, Int32
srcunit, HandleRef imageAttributes, DrawImageAbort callback, HandleRef
callbackdata)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect,
Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit
srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr
callbackData)
at System.Drawing.Bitmap.MakeTransparent(Color transparentColor)
at System.Drawing.Bitmap.MakeTransparent()
at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
at System.Windows.Forms.ThreadContext.OnThreadExcepti on(Exception t)
at System.Windows.Forms.Control.WndProcException(Exce ption e)
at System.Windows.Forms.ControlNativeWindow.OnThreadE xception(Exception e)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at
CheckManager.ChequePrinting.New_GUI.Controls.Check RunReport.mi_PrintPreview_Click(Object sender, EventArgs e)
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItemData.Execute()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

System.InvalidOperationException: The object is currently in use elsewhere.
at System.Drawing.Graphics.Dispose(Boolean disposing)
at System.Drawing.Graphics.Dispose()
at
Infragistics.Win.DrawCache.DisposeNativeWindowMeth ods(NativeMemoryDCData&
data)
at Infragistics.Win.DrawCache.FreeState()
at Infragistics.Win.DrawCache.Dispose()
at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle
invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode,
Boolean clipText, Boolean forceDrawAsFocused)
at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle
invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode, Size elementSize)
at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode)
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.D raw(Graphics
graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode)
at Infragistics.Win.UltraControlBase.OnPaint(PaintEve ntArgs pe)
at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(Pa intEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandlin g(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(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Are you using CreateGraphics somewhere??

See the GDI+ FAQ on how and where to get Graphics objects.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
I'm writing a program that deals extensively with the printer. For the
most
part my application runs fine, but occasionally I run into some
Exceptions.
The most common exceptions I run into are NullReferenceException and
InvalidOperationException : The object is currently in use elsewhere.
Unfortunately this appears to be a race condition. These exceptions
appear
to ocurr while disposing GDI+ objects, the Graphics object seems to be the
biggest culprit. Unfortunately all of these Exceptions ocurr in
System.Drawing.dll, as a result no source code is avaialable. These
Exceptions always ocurr while my program is printing. I would provide the
source code for this, but these Exceptions are blown during various
portions
of my printing algorithm (approximately 3,000 lines), and exposing that
would
put my job in jeapordy. I'm hoping that someone out there is familiar
enough
with GDI+ to know why these Exceptions are being thrown. Any help would
be
appreciated.

Here is the stack trace for my exceptions:

************** Exception Text **************
System.InvalidOperationException: The object is currently in use
elsewhere.
at System.Drawing.Graphics.Dispose(Boolean disposing)
at System.Drawing.Graphics.Dispose()
at System.Drawing.Printing.PrintController.PrintLoop( PrintDocument
document)
at System.Drawing.Printing.PrintController.Print(Prin tDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Erudite.CheckManagerSystem.CheckRunPrinter.BeginPr inting()
at
CheckManager.ChequePrinting.New_GUI.PrintForm.Prin tingDataLoaded(CheckRun
checkRun, DataLoadedEventArgs args)
at
Erudite.CheckManagerSystem.CheckRun.OnDataLoaded(C HECK_HEADERDataTable
checkHeaders)
at Erudite.CheckManagerSystem.CheckRun.LoadData(Check Type checkType)
at
Erudite.CheckManagerSystem.CheckRun.LoadHeaderData (CheckRunEventHandler
beginLoadingDataCallback, CheckRunDataLoadedHandler dataLoadedCallback)
at CheckManager.ChequePrinting.New_GUI.PrintForm.ubtn _Print_Click(Object
sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButtonBase.OnClick(Even tArgs e)
at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseE ventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
************** Exception Text **************
System.ArgumentException: Invalid parameter used.
at System.Drawing.Image.get_FrameDimensionsList()
at System.Drawing.ImageAnimator.CanAnimate(Image image)
at System.Drawing.ImageInfo..ctor(Image image)
at System.Drawing.ImageAnimator.Animate(Image image, EventHandler
onFrameChangedHandler)
at System.Windows.Forms.PictureBox.Animate(Boolean animate)
at System.Windows.Forms.PictureBox.Animate()
at System.Windows.Forms.PictureBox.OnVisibleChanged(E ventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChange d(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(Even tArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleCh anged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventAr gs e)
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

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

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of
an
object.
at System.Drawing.SafeNativeMethods.GdipDrawImageRect RectI(HandleRef
graphics, HandleRef image, Int32 dstx, Int32 dsty, Int32 dstwidth, Int32
dstheight, Int32 srcx, Int32 srcy, Int32 srcwidth, Int32 srcheight, Int32
srcunit, HandleRef imageAttributes, DrawImageAbort callback, HandleRef
callbackdata)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect,
Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit
srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr
callbackData)
at System.Drawing.Bitmap.MakeTransparent(Color transparentColor)
at System.Drawing.Bitmap.MakeTransparent()
at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
at System.Windows.Forms.ThreadContext.OnThreadExcepti on(Exception t)
at System.Windows.Forms.Control.WndProcException(Exce ption e)
at System.Windows.Forms.ControlNativeWindow.OnThreadE xception(Exception
e)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at
CheckManager.ChequePrinting.New_GUI.Controls.Check RunReport.mi_PrintPreview_Click(Object
sender, EventArgs e)
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItemData.Execute()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

System.InvalidOperationException: The object is currently in use
elsewhere.
at System.Drawing.Graphics.Dispose(Boolean disposing)
at System.Drawing.Graphics.Dispose()
at
Infragistics.Win.DrawCache.DisposeNativeWindowMeth ods(NativeMemoryDCData&
data)
at Infragistics.Win.DrawCache.FreeState()
at Infragistics.Win.DrawCache.Dispose()
at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle
invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode,
Boolean clipText, Boolean forceDrawAsFocused)
at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle
invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode, Size elementSize)
at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode)
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.D raw(Graphics
graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode)
at Infragistics.Win.UltraControlBase.OnPaint(PaintEve ntArgs pe)
at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(Pa intEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandlin g(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(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

Nov 16 '05 #2

P: n/a
No I am not using CreateGraphics. I'm using the Graphics object that is
passed in the PagePrintEventArgs parameter of the PrintPage event of
PrintDocument.

"Bob Powell [MVP]" wrote:
Are you using CreateGraphics somewhere??

See the GDI+ FAQ on how and where to get Graphics objects.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
I'm writing a program that deals extensively with the printer. For the
most
part my application runs fine, but occasionally I run into some
Exceptions.
The most common exceptions I run into are NullReferenceException and
InvalidOperationException : The object is currently in use elsewhere.
Unfortunately this appears to be a race condition. These exceptions
appear
to ocurr while disposing GDI+ objects, the Graphics object seems to be the
biggest culprit. Unfortunately all of these Exceptions ocurr in
System.Drawing.dll, as a result no source code is avaialable. These
Exceptions always ocurr while my program is printing. I would provide the
source code for this, but these Exceptions are blown during various
portions
of my printing algorithm (approximately 3,000 lines), and exposing that
would
put my job in jeapordy. I'm hoping that someone out there is familiar
enough
with GDI+ to know why these Exceptions are being thrown. Any help would
be
appreciated.

Here is the stack trace for my exceptions:

************** Exception Text **************
System.InvalidOperationException: The object is currently in use
elsewhere.
at System.Drawing.Graphics.Dispose(Boolean disposing)
at System.Drawing.Graphics.Dispose()
at System.Drawing.Printing.PrintController.PrintLoop( PrintDocument
document)
at System.Drawing.Printing.PrintController.Print(Prin tDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at Erudite.CheckManagerSystem.CheckRunPrinter.BeginPr inting()
at
CheckManager.ChequePrinting.New_GUI.PrintForm.Prin tingDataLoaded(CheckRun
checkRun, DataLoadedEventArgs args)
at
Erudite.CheckManagerSystem.CheckRun.OnDataLoaded(C HECK_HEADERDataTable
checkHeaders)
at Erudite.CheckManagerSystem.CheckRun.LoadData(Check Type checkType)
at
Erudite.CheckManagerSystem.CheckRun.LoadHeaderData (CheckRunEventHandler
beginLoadingDataCallback, CheckRunDataLoadedHandler dataLoadedCallback)
at CheckManager.ChequePrinting.New_GUI.PrintForm.ubtn _Print_Click(Object
sender, EventArgs e)
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at Infragistics.Win.Misc.UltraButtonBase.OnClick(Even tArgs e)
at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseE ventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
************** Exception Text **************
System.ArgumentException: Invalid parameter used.
at System.Drawing.Image.get_FrameDimensionsList()
at System.Drawing.ImageAnimator.CanAnimate(Image image)
at System.Drawing.ImageInfo..ctor(Image image)
at System.Drawing.ImageAnimator.Animate(Image image, EventHandler
onFrameChangedHandler)
at System.Windows.Forms.PictureBox.Animate(Boolean animate)
at System.Windows.Forms.PictureBox.Animate()
at System.Windows.Forms.PictureBox.OnVisibleChanged(E ventArgs e)
at System.Windows.Forms.Control.OnParentVisibleChange d(EventArgs e)
at System.Windows.Forms.Control.OnVisibleChanged(Even tArgs e)
at System.Windows.Forms.ScrollableControl.OnVisibleCh anged(EventArgs e)
at System.Windows.Forms.Form.OnVisibleChanged(EventAr gs e)
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

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

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of
an
object.
at System.Drawing.SafeNativeMethods.GdipDrawImageRect RectI(HandleRef
graphics, HandleRef image, Int32 dstx, Int32 dsty, Int32 dstwidth, Int32
dstheight, Int32 srcx, Int32 srcy, Int32 srcwidth, Int32 srcheight, Int32
srcunit, HandleRef imageAttributes, DrawImageAbort callback, HandleRef
callbackdata)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect,
Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit
srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr
callbackData)
at System.Drawing.Bitmap.MakeTransparent(Color transparentColor)
at System.Drawing.Bitmap.MakeTransparent()
at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
at System.Windows.Forms.ThreadContext.OnThreadExcepti on(Exception t)
at System.Windows.Forms.Control.WndProcException(Exce ption e)
at System.Windows.Forms.ControlNativeWindow.OnThreadE xception(Exception
e)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at
CheckManager.ChequePrinting.New_GUI.Controls.Check RunReport.mi_PrintPreview_Click(Object
sender, EventArgs e)
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItemData.Execute()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

System.InvalidOperationException: The object is currently in use
elsewhere.
at System.Drawing.Graphics.Dispose(Boolean disposing)
at System.Drawing.Graphics.Dispose()
at
Infragistics.Win.DrawCache.DisposeNativeWindowMeth ods(NativeMemoryDCData&
data)
at Infragistics.Win.DrawCache.FreeState()
at Infragistics.Win.DrawCache.Dispose()
at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle
invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode,
Boolean clipText, Boolean forceDrawAsFocused)
at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle
invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode, Size elementSize)
at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode)
at Infragistics.Win.UltraWinGrid.UltraGridUIElement.D raw(Graphics
graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
alphaBlendMode)
at Infragistics.Win.UltraControlBase.OnPaint(PaintEve ntArgs pe)
at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(Pa intEventArgs pe)
at System.Windows.Forms.Control.PaintWithErrorHandlin g(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(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)


Nov 16 '05 #3

P: n/a
It seems to me that you are trying to call Dispose() on the Graphics object
that is passed as a parameter to your method. If this is true, I would
remove the Dispose() call. It looks like you are attempting to Dispose a
Graphics object that is still being used by your application - hence the in
use and null reference errors.

As far as the other one - the Animate() that is too hard to tell because I
can't see what you are passing into the function call.

Hope this helps.
"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
No I am not using CreateGraphics. I'm using the Graphics object that is
passed in the PagePrintEventArgs parameter of the PrintPage event of
PrintDocument.

"Bob Powell [MVP]" wrote:
Are you using CreateGraphics somewhere??

See the GDI+ FAQ on how and where to get Graphics objects.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
> I'm writing a program that deals extensively with the printer. For the
> most
> part my application runs fine, but occasionally I run into some
> Exceptions.
> The most common exceptions I run into are NullReferenceException and
> InvalidOperationException : The object is currently in use elsewhere.
> Unfortunately this appears to be a race condition. These exceptions
> appear
> to ocurr while disposing GDI+ objects, the Graphics object seems to be
> the
> biggest culprit. Unfortunately all of these Exceptions ocurr in
> System.Drawing.dll, as a result no source code is avaialable. These
> Exceptions always ocurr while my program is printing. I would provide
> the
> source code for this, but these Exceptions are blown during various
> portions
> of my printing algorithm (approximately 3,000 lines), and exposing that
> would
> put my job in jeapordy. I'm hoping that someone out there is familiar
> enough
> with GDI+ to know why these Exceptions are being thrown. Any help
> would
> be
> appreciated.
>
> Here is the stack trace for my exceptions:
>
> ************** Exception Text **************
> System.InvalidOperationException: The object is currently in use
> elsewhere.
> at System.Drawing.Graphics.Dispose(Boolean disposing)
> at System.Drawing.Graphics.Dispose()
> at System.Drawing.Printing.PrintController.PrintLoop( PrintDocument
> document)
> at System.Drawing.Printing.PrintController.Print(Prin tDocument
> document)
> at System.Drawing.Printing.PrintDocument.Print()
> at Erudite.CheckManagerSystem.CheckRunPrinter.BeginPr inting()
> at
> CheckManager.ChequePrinting.New_GUI.PrintForm.Prin tingDataLoaded(CheckRun
> checkRun, DataLoadedEventArgs args)
> at
> Erudite.CheckManagerSystem.CheckRun.OnDataLoaded(C HECK_HEADERDataTable
> checkHeaders)
> at Erudite.CheckManagerSystem.CheckRun.LoadData(Check Type checkType)
> at
> Erudite.CheckManagerSystem.CheckRun.LoadHeaderData (CheckRunEventHandler
> beginLoadingDataCallback, CheckRunDataLoadedHandler dataLoadedCallback)
> at
> CheckManager.ChequePrinting.New_GUI.PrintForm.ubtn _Print_Click(Object
> sender, EventArgs e)
> at System.EventHandler.Invoke(Object sender, EventArgs e)
> at System.Windows.Forms.Control.OnClick(EventArgs e)
> at Infragistics.Win.Misc.UltraButtonBase.OnClick(Even tArgs e)
> at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseE ventArgs e)
> at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
> button, Int32 clicks)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>
>
> ************** Exception Text **************
> System.ArgumentException: Invalid parameter used.
> at System.Drawing.Image.get_FrameDimensionsList()
> at System.Drawing.ImageAnimator.CanAnimate(Image image)
> at System.Drawing.ImageInfo..ctor(Image image)
> at System.Drawing.ImageAnimator.Animate(Image image, EventHandler
> onFrameChangedHandler)
> at System.Windows.Forms.PictureBox.Animate(Boolean animate)
> at System.Windows.Forms.PictureBox.Animate()
> at System.Windows.Forms.PictureBox.OnVisibleChanged(E ventArgs e)
> at System.Windows.Forms.Control.OnParentVisibleChange d(EventArgs e)
> at System.Windows.Forms.Control.OnVisibleChanged(Even tArgs e)
> at System.Windows.Forms.ScrollableControl.OnVisibleCh anged(EventArgs
> e)
> at System.Windows.Forms.Form.OnVisibleChanged(EventAr gs e)
> at System.Windows.Forms.Control.WmShowWindow(Message& m)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
> at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
> at System.Windows.Forms.Form.WmShowWindow(Message& m)
> at System.Windows.Forms.Form.WndProc(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>
>
>
> See the end of this message for details on invoking
> just-in-time (JIT) debugging instead of this dialog box.
>
> ************** Exception Text **************
> System.NullReferenceException: Object reference not set to an instance
> of
> an
> object.
> at System.Drawing.SafeNativeMethods.GdipDrawImageRect RectI(HandleRef
> graphics, HandleRef image, Int32 dstx, Int32 dsty, Int32 dstwidth,
> Int32
> dstheight, Int32 srcx, Int32 srcy, Int32 srcwidth, Int32 srcheight,
> Int32
> srcunit, HandleRef imageAttributes, DrawImageAbort callback, HandleRef
> callbackdata)
> at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect,
> Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit
> srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr
> callbackData)
> at System.Drawing.Bitmap.MakeTransparent(Color transparentColor)
> at System.Drawing.Bitmap.MakeTransparent()
> at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
> at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
> at System.Windows.Forms.ThreadContext.OnThreadExcepti on(Exception t)
> at System.Windows.Forms.Control.WndProcException(Exce ption e)
> at
> System.Windows.Forms.ControlNativeWindow.OnThreadE xception(Exception
> e)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
> at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
> msg)
> at
> System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
> dwComponentID, Int32 reason, Int32 pvLoopData)
> at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32
> reason,
> ApplicationContext context)
> at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
> ApplicationContext context)
> at System.Windows.Forms.Application.RunDialog(Form form)
> at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
> at System.Windows.Forms.Form.ShowDialog()
> at
> CheckManager.ChequePrinting.New_GUI.Controls.Check RunReport.mi_PrintPreview_Click(Object
> sender, EventArgs e)
> at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
> at System.Windows.Forms.MenuItemData.Execute()
> at System.Windows.Forms.Command.Invoke()
> at System.Windows.Forms.Control.WmCommand(Message& m)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>
> System.InvalidOperationException: The object is currently in use
> elsewhere.
> at System.Drawing.Graphics.Dispose(Boolean disposing)
> at System.Drawing.Graphics.Dispose()
> at
> Infragistics.Win.DrawCache.DisposeNativeWindowMeth ods(NativeMemoryDCData&
> data)
> at Infragistics.Win.DrawCache.FreeState()
> at Infragistics.Win.DrawCache.Dispose()
> at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle
> invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode,
> Boolean clipText, Boolean forceDrawAsFocused)
> at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle
> invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
> at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
> Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
> alphaBlendMode, Size elementSize)
> at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
> Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
> alphaBlendMode)
> at Infragistics.Win.UltraWinGrid.UltraGridUIElement.D raw(Graphics
> graphics, Rectangle invalidRectangle, Boolean doubleBuffer,
> AlphaBlendMode
> alphaBlendMode)
> at Infragistics.Win.UltraControlBase.OnPaint(PaintEve ntArgs pe)
> at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(Pa intEventArgs pe)
> at System.Windows.Forms.Control.PaintWithErrorHandlin g(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(M essage& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>


Nov 16 '05 #4

P: n/a
That does help. I'm not disposing the Graphics object, but I am disposing a
lot of different GDI objects. I'm almost certain that some of these GDI
objects are system objects, ie System Brushes, and System Pens.

"Nathan Neitzke" wrote:
It seems to me that you are trying to call Dispose() on the Graphics object
that is passed as a parameter to your method. If this is true, I would
remove the Dispose() call. It looks like you are attempting to Dispose a
Graphics object that is still being used by your application - hence the in
use and null reference errors.

As far as the other one - the Animate() that is too hard to tell because I
can't see what you are passing into the function call.

Hope this helps.
"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
No I am not using CreateGraphics. I'm using the Graphics object that is
passed in the PagePrintEventArgs parameter of the PrintPage event of
PrintDocument.

"Bob Powell [MVP]" wrote:
Are you using CreateGraphics somewhere??

See the GDI+ FAQ on how and where to get Graphics objects.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
> I'm writing a program that deals extensively with the printer. For the
> most
> part my application runs fine, but occasionally I run into some
> Exceptions.
> The most common exceptions I run into are NullReferenceException and
> InvalidOperationException : The object is currently in use elsewhere.
> Unfortunately this appears to be a race condition. These exceptions
> appear
> to ocurr while disposing GDI+ objects, the Graphics object seems to be
> the
> biggest culprit. Unfortunately all of these Exceptions ocurr in
> System.Drawing.dll, as a result no source code is avaialable. These
> Exceptions always ocurr while my program is printing. I would provide
> the
> source code for this, but these Exceptions are blown during various
> portions
> of my printing algorithm (approximately 3,000 lines), and exposing that
> would
> put my job in jeapordy. I'm hoping that someone out there is familiar
> enough
> with GDI+ to know why these Exceptions are being thrown. Any help
> would
> be
> appreciated.
>
> Here is the stack trace for my exceptions:
>
> ************** Exception Text **************
> System.InvalidOperationException: The object is currently in use
> elsewhere.
> at System.Drawing.Graphics.Dispose(Boolean disposing)
> at System.Drawing.Graphics.Dispose()
> at System.Drawing.Printing.PrintController.PrintLoop( PrintDocument
> document)
> at System.Drawing.Printing.PrintController.Print(Prin tDocument
> document)
> at System.Drawing.Printing.PrintDocument.Print()
> at Erudite.CheckManagerSystem.CheckRunPrinter.BeginPr inting()
> at
> CheckManager.ChequePrinting.New_GUI.PrintForm.Prin tingDataLoaded(CheckRun
> checkRun, DataLoadedEventArgs args)
> at
> Erudite.CheckManagerSystem.CheckRun.OnDataLoaded(C HECK_HEADERDataTable
> checkHeaders)
> at Erudite.CheckManagerSystem.CheckRun.LoadData(Check Type checkType)
> at
> Erudite.CheckManagerSystem.CheckRun.LoadHeaderData (CheckRunEventHandler
> beginLoadingDataCallback, CheckRunDataLoadedHandler dataLoadedCallback)
> at
> CheckManager.ChequePrinting.New_GUI.PrintForm.ubtn _Print_Click(Object
> sender, EventArgs e)
> at System.EventHandler.Invoke(Object sender, EventArgs e)
> at System.Windows.Forms.Control.OnClick(EventArgs e)
> at Infragistics.Win.Misc.UltraButtonBase.OnClick(Even tArgs e)
> at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseE ventArgs e)
> at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
> button, Int32 clicks)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>
>
> ************** Exception Text **************
> System.ArgumentException: Invalid parameter used.
> at System.Drawing.Image.get_FrameDimensionsList()
> at System.Drawing.ImageAnimator.CanAnimate(Image image)
> at System.Drawing.ImageInfo..ctor(Image image)
> at System.Drawing.ImageAnimator.Animate(Image image, EventHandler
> onFrameChangedHandler)
> at System.Windows.Forms.PictureBox.Animate(Boolean animate)
> at System.Windows.Forms.PictureBox.Animate()
> at System.Windows.Forms.PictureBox.OnVisibleChanged(E ventArgs e)
> at System.Windows.Forms.Control.OnParentVisibleChange d(EventArgs e)
> at System.Windows.Forms.Control.OnVisibleChanged(Even tArgs e)
> at System.Windows.Forms.ScrollableControl.OnVisibleCh anged(EventArgs
> e)
> at System.Windows.Forms.Form.OnVisibleChanged(EventAr gs e)
> at System.Windows.Forms.Control.WmShowWindow(Message& m)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
> at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
> at System.Windows.Forms.Form.WmShowWindow(Message& m)
> at System.Windows.Forms.Form.WndProc(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>
>
>
> See the end of this message for details on invoking
> just-in-time (JIT) debugging instead of this dialog box.
>
> ************** Exception Text **************
> System.NullReferenceException: Object reference not set to an instance
> of
> an
> object.
> at System.Drawing.SafeNativeMethods.GdipDrawImageRect RectI(HandleRef
> graphics, HandleRef image, Int32 dstx, Int32 dsty, Int32 dstwidth,
> Int32
> dstheight, Int32 srcx, Int32 srcy, Int32 srcwidth, Int32 srcheight,
> Int32
> srcunit, HandleRef imageAttributes, DrawImageAbort callback, HandleRef
> callbackdata)
> at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect,
> Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit
> srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr
> callbackData)
> at System.Drawing.Bitmap.MakeTransparent(Color transparentColor)
> at System.Drawing.Bitmap.MakeTransparent()
> at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
> at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
> at System.Windows.Forms.ThreadContext.OnThreadExcepti on(Exception t)
> at System.Windows.Forms.Control.WndProcException(Exce ption e)
> at
> System.Windows.Forms.ControlNativeWindow.OnThreadE xception(Exception
> e)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
> at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
> msg)
> at
> System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
> dwComponentID, Int32 reason, Int32 pvLoopData)
> at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32
> reason,
> ApplicationContext context)
> at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
> ApplicationContext context)
> at System.Windows.Forms.Application.RunDialog(Form form)
> at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
> at System.Windows.Forms.Form.ShowDialog()
> at
> CheckManager.ChequePrinting.New_GUI.Controls.Check RunReport.mi_PrintPreview_Click(Object
> sender, EventArgs e)
> at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
> at System.Windows.Forms.MenuItemData.Execute()
> at System.Windows.Forms.Command.Invoke()
> at System.Windows.Forms.Control.WmCommand(Message& m)
> at System.Windows.Forms.Control.WndProc(Message& m)
> at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
> at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>
> System.InvalidOperationException: The object is currently in use
> elsewhere.
> at System.Drawing.Graphics.Dispose(Boolean disposing)
> at System.Drawing.Graphics.Dispose()
> at
> Infragistics.Win.DrawCache.DisposeNativeWindowMeth ods(NativeMemoryDCData&
> data)
> at Infragistics.Win.DrawCache.FreeState()
> at Infragistics.Win.DrawCache.Dispose()
> at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle
> invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode,
> Boolean clipText, Boolean forceDrawAsFocused)
> at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle
> invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode)
> at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
> Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
> alphaBlendMode, Size elementSize)
> at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
> Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
> alphaBlendMode)
> at Infragistics.Win.UltraWinGrid.UltraGridUIElement.D raw(Graphics
> graphics, Rectangle invalidRectangle, Boolean doubleBuffer,
> AlphaBlendMode
> alphaBlendMode)
> at Infragistics.Win.UltraControlBase.OnPaint(PaintEve ntArgs pe)
> at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(Pa intEventArgs pe)
> at System.Windows.Forms.Control.PaintWithErrorHandlin g(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(M essage& m)
> at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
> IntPtr wparam, IntPtr lparam)
>


Nov 16 '05 #5

P: n/a
Oh,
Yes, definately - never Dispose System GDI objects. Only Dispose GDI
objects that you explicitly create.

Glad I was able to help.

Take care.

--
Nathan

"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:5C**********************************@microsof t.com...
That does help. I'm not disposing the Graphics object, but I am disposing
a
lot of different GDI objects. I'm almost certain that some of these GDI
objects are system objects, ie System Brushes, and System Pens.

"Nathan Neitzke" wrote:
It seems to me that you are trying to call Dispose() on the Graphics
object
that is passed as a parameter to your method. If this is true, I would
remove the Dispose() call. It looks like you are attempting to Dispose a
Graphics object that is still being used by your application - hence the
in
use and null reference errors.

As far as the other one - the Animate() that is too hard to tell because
I
can't see what you are passing into the function call.

Hope this helps.
"anonymous" <an*******@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
> No I am not using CreateGraphics. I'm using the Graphics object that
> is
> passed in the PagePrintEventArgs parameter of the PrintPage event of
> PrintDocument.
>
> "Bob Powell [MVP]" wrote:
>
>> Are you using CreateGraphics somewhere??
>>
>> See the GDI+ FAQ on how and where to get Graphics objects.
>>
>> --
>> Bob Powell [MVP]
>> Visual C#, System.Drawing
>>
>> Find great Windows Forms articles in Windows Forms Tips and Tricks
>> http://www.bobpowell.net/tipstricks.htm
>>
>> Answer those GDI+ questions with the GDI+ FAQ
>> http://www.bobpowell.net/faqmain.htm
>>
>> All new articles provide code in C# and VB.NET.
>> Subscribe to the RSS feeds provided and never miss a new article.
>>
>>
>>
>>
>>
>> "anonymous" <an*******@discussions.microsoft.com> wrote in message
>> news:BB**********************************@microsof t.com...
>> > I'm writing a program that deals extensively with the printer. For
>> > the
>> > most
>> > part my application runs fine, but occasionally I run into some
>> > Exceptions.
>> > The most common exceptions I run into are NullReferenceException and
>> > InvalidOperationException : The object is currently in use
>> > elsewhere.
>> > Unfortunately this appears to be a race condition. These exceptions
>> > appear
>> > to ocurr while disposing GDI+ objects, the Graphics object seems to
>> > be
>> > the
>> > biggest culprit. Unfortunately all of these Exceptions ocurr in
>> > System.Drawing.dll, as a result no source code is avaialable. These
>> > Exceptions always ocurr while my program is printing. I would
>> > provide
>> > the
>> > source code for this, but these Exceptions are blown during various
>> > portions
>> > of my printing algorithm (approximately 3,000 lines), and exposing
>> > that
>> > would
>> > put my job in jeapordy. I'm hoping that someone out there is
>> > familiar
>> > enough
>> > with GDI+ to know why these Exceptions are being thrown. Any help
>> > would
>> > be
>> > appreciated.
>> >
>> > Here is the stack trace for my exceptions:
>> >
>> > ************** Exception Text **************
>> > System.InvalidOperationException: The object is currently in use
>> > elsewhere.
>> > at System.Drawing.Graphics.Dispose(Boolean disposing)
>> > at System.Drawing.Graphics.Dispose()
>> > at System.Drawing.Printing.PrintController.PrintLoop( PrintDocument
>> > document)
>> > at System.Drawing.Printing.PrintController.Print(Prin tDocument
>> > document)
>> > at System.Drawing.Printing.PrintDocument.Print()
>> > at Erudite.CheckManagerSystem.CheckRunPrinter.BeginPr inting()
>> > at
>> > CheckManager.ChequePrinting.New_GUI.PrintForm.Prin tingDataLoaded(CheckRun
>> > checkRun, DataLoadedEventArgs args)
>> > at
>> > Erudite.CheckManagerSystem.CheckRun.OnDataLoaded(C HECK_HEADERDataTable
>> > checkHeaders)
>> > at Erudite.CheckManagerSystem.CheckRun.LoadData(Check Type
>> > checkType)
>> > at
>> > Erudite.CheckManagerSystem.CheckRun.LoadHeaderData (CheckRunEventHandler
>> > beginLoadingDataCallback, CheckRunDataLoadedHandler
>> > dataLoadedCallback)
>> > at
>> > CheckManager.ChequePrinting.New_GUI.PrintForm.ubtn _Print_Click(Object
>> > sender, EventArgs e)
>> > at System.EventHandler.Invoke(Object sender, EventArgs e)
>> > at System.Windows.Forms.Control.OnClick(EventArgs e)
>> > at Infragistics.Win.Misc.UltraButtonBase.OnClick(Even tArgs e)
>> > at Infragistics.Win.Misc.UltraButton.OnMouseUp(MouseE ventArgs e)
>> > at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
>> > button, Int32 clicks)
>> > at System.Windows.Forms.Control.WndProc(Message& m)
>> > at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
>> > at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
>> > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
>> > msg,
>> > IntPtr wparam, IntPtr lparam)
>> >
>> >
>> > ************** Exception Text **************
>> > System.ArgumentException: Invalid parameter used.
>> > at System.Drawing.Image.get_FrameDimensionsList()
>> > at System.Drawing.ImageAnimator.CanAnimate(Image image)
>> > at System.Drawing.ImageInfo..ctor(Image image)
>> > at System.Drawing.ImageAnimator.Animate(Image image, EventHandler
>> > onFrameChangedHandler)
>> > at System.Windows.Forms.PictureBox.Animate(Boolean animate)
>> > at System.Windows.Forms.PictureBox.Animate()
>> > at System.Windows.Forms.PictureBox.OnVisibleChanged(E ventArgs e)
>> > at System.Windows.Forms.Control.OnParentVisibleChange d(EventArgs
>> > e)
>> > at System.Windows.Forms.Control.OnVisibleChanged(Even tArgs e)
>> > at
>> > System.Windows.Forms.ScrollableControl.OnVisibleCh anged(EventArgs
>> > e)
>> > at System.Windows.Forms.Form.OnVisibleChanged(EventAr gs e)
>> > at System.Windows.Forms.Control.WmShowWindow(Message& m)
>> > at System.Windows.Forms.Control.WndProc(Message& m)
>> > at System.Windows.Forms.ScrollableControl.WndProc(Mes sage& m)
>> > at System.Windows.Forms.ContainerControl.WndProc(Mess age& m)
>> > at System.Windows.Forms.Form.WmShowWindow(Message& m)
>> > at System.Windows.Forms.Form.WndProc(Message& m)
>> > at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
>> > at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
>> > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
>> > msg,
>> > IntPtr wparam, IntPtr lparam)
>> >
>> >
>> >
>> > See the end of this message for details on invoking
>> > just-in-time (JIT) debugging instead of this dialog box.
>> >
>> > ************** Exception Text **************
>> > System.NullReferenceException: Object reference not set to an
>> > instance
>> > of
>> > an
>> > object.
>> > at
>> > System.Drawing.SafeNativeMethods.GdipDrawImageRect RectI(HandleRef
>> > graphics, HandleRef image, Int32 dstx, Int32 dsty, Int32 dstwidth,
>> > Int32
>> > dstheight, Int32 srcx, Int32 srcy, Int32 srcwidth, Int32 srcheight,
>> > Int32
>> > srcunit, HandleRef imageAttributes, DrawImageAbort callback,
>> > HandleRef
>> > callbackdata)
>> > at System.Drawing.Graphics.DrawImage(Image image, Rectangle
>> > destRect,
>> > Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight,
>> > GraphicsUnit
>> > srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr
>> > callbackData)
>> > at System.Drawing.Bitmap.MakeTransparent(Color transparentColor)
>> > at System.Drawing.Bitmap.MakeTransparent()
>> > at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
>> > at System.Windows.Forms.ThreadExceptionDialog..ctor(E xception t)
>> > at System.Windows.Forms.ThreadContext.OnThreadExcepti on(Exception
>> > t)
>> > at System.Windows.Forms.Control.WndProcException(Exce ption e)
>> > at
>> > System.Windows.Forms.ControlNativeWindow.OnThreadE xception(Exception
>> > e)
>> > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
>> > msg,
>> > IntPtr wparam, IntPtr lparam)
>> > at System.Windows.Forms.UnsafeNativeMethods.DispatchM essageW(MSG&
>> > msg)
>> > at
>> > System.Windows.Forms.ComponentManager.System.Windo ws.Forms.UnsafeNativeMethods+IMsoComponentManager. FPushMessageLoop(Int32
>> > dwComponentID, Int32 reason, Int32 pvLoopData)
>> > at System.Windows.Forms.ThreadContext.RunMessageLoopI nner(Int32
>> > reason,
>> > ApplicationContext context)
>> > at System.Windows.Forms.ThreadContext.RunMessageLoop( Int32 reason,
>> > ApplicationContext context)
>> > at System.Windows.Forms.Application.RunDialog(Form form)
>> > at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
>> > at System.Windows.Forms.Form.ShowDialog()
>> > at
>> > CheckManager.ChequePrinting.New_GUI.Controls.Check RunReport.mi_PrintPreview_Click(Object
>> > sender, EventArgs e)
>> > at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
>> > at System.Windows.Forms.MenuItemData.Execute()
>> > at System.Windows.Forms.Command.Invoke()
>> > at System.Windows.Forms.Control.WmCommand(Message& m)
>> > at System.Windows.Forms.Control.WndProc(Message& m)
>> > at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
>> > at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
>> > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
>> > msg,
>> > IntPtr wparam, IntPtr lparam)
>> >
>> > System.InvalidOperationException: The object is currently in use
>> > elsewhere.
>> > at System.Drawing.Graphics.Dispose(Boolean disposing)
>> > at System.Drawing.Graphics.Dispose()
>> > at
>> > Infragistics.Win.DrawCache.DisposeNativeWindowMeth ods(NativeMemoryDCData&
>> > data)
>> > at Infragistics.Win.DrawCache.FreeState()
>> > at Infragistics.Win.DrawCache.Dispose()
>> > at Infragistics.Win.UIElement.DrawHelper(Graphics graphics,
>> > Rectangle
>> > invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
>> > alphaBlendMode,
>> > Boolean clipText, Boolean forceDrawAsFocused)
>> > at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle
>> > invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
>> > alphaBlendMode)
>> > at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
>> > Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
>> > alphaBlendMode, Size elementSize)
>> > at Infragistics.Win.ControlUIElementBase.Draw(Graphic s graphics,
>> > Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode
>> > alphaBlendMode)
>> > at Infragistics.Win.UltraWinGrid.UltraGridUIElement.D raw(Graphics
>> > graphics, Rectangle invalidRectangle, Boolean doubleBuffer,
>> > AlphaBlendMode
>> > alphaBlendMode)
>> > at Infragistics.Win.UltraControlBase.OnPaint(PaintEve ntArgs pe)
>> > at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(Pa intEventArgs
>> > pe)
>> > at
>> > System.Windows.Forms.Control.PaintWithErrorHandlin g(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(M essage& m)
>> > at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
>> > msg,
>> > IntPtr wparam, IntPtr lparam)
>> >
>>
>>
>>


Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.