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) 5 4114
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)
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)
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) >
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) >
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) >> > >> >> >> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: GIMME |
last post by:
One of my coworkers insists that one should never use
static methods because race conditions exist. Thinking
along the lines that all variable assignments are
assignments to static variables.
...
|
by: Juergen Stein |
last post by:
Hi Group,
I couldn't find an answer on this with Google, so let me test you :)
I've a fairly complex WebApp, and I put most of the JS code in
independent external .js files. One of these...
|
by: fran |
last post by:
Server: IBM XSERIES 225 (Intel Xeon CPU 2.40GHz 1GB RAM)
Operating System: Linux RedHat ES 2.1 kernel 2.4.9
Languaje: C++
Compiler: gcc 2.96
Libs: pthread
We are in need of your help in...
|
by: Richard |
last post by:
Hi,
I'm suffering a socket race condition - I think. The code works fine at
full speed on a single CPU machine. However when I run full speed on a 2
Zeon machine the socket drops data on an...
|
by: Urs Vogel |
last post by:
Hi
I wrote an application server (a remoting sinlgeton), where processes must
be stopped in very rare cases, done thru a Thread.Abort(). Occasionally, and
only after a Thread.Abort(), this...
|
by: Ryan Liu |
last post by:
Hi,
What does ArrayList.Synchronized really do for an ArrayList?
Is that equal to add lock(this) for all its public methods and properties?
Not just for Add()/Insert()/Remvoe()/Count, but also...
|
by: chris johnson |
last post by:
Hello there.
I have a script (say, page.js) called from a script tag as such:
<script src="page.js"></script>
Within page.js, I have something like the following:
...
|
by: antonyliu2002 |
last post by:
I do not quite understand the race condition.
As I posted a couple of days ago, I create a PDF on the fly in my web
application at regular intervals. Users will be able to download the
PDF...
|
by: Berryl Hesh |
last post by:
I wouldn't nomally post this here, as it has something to do with the
ListView control usage I think, or maybe with a race condition or some
windoes messaging. I'm just not sure.
The test below...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |