generic error in GDI+ occurs when drawing windows metafile

G

Guest

I am getting a sporadic external exception when drawing a windows metafile.
The odd part about this is that the problem only occurs about one out a
thousand times this code executes, and its the same metafiles that are always
used (so it doesn't appear to be a problem with the metafile itself.) The
code is as follows:

private void PrintLogo(Graphics graphics)
{
//graphics.PageUnit = GraphicsUnit.Display;
ResetTransform( graphics, true );
using(Metafile logo = new Metafile(_printer.LogoImagePath))
{
graphics.DrawImage(logo, 0, 0, LOGO_WIDTH, LOGO_HEIGHT);
}
if(_printer.Report.Type.DrawLogoSeparator)
{
graphics.DrawLine(new Pen(new SolidBrush(Color.Black), 1.0F), 0,
LOGO_HEIGHT, graphics.VisibleClipBounds.Width, LOGO_HEIGHT);
graphics.DrawLine(new Pen(new SolidBrush(Color.Black), 1.0F), 0,
LOGO_HEIGHT + 2, graphics.VisibleClipBounds.Width, LOGO_HEIGHT + 2.0F);
}
}



The exception is as follows:

Event Type: Error
Event Source: Traffic Print Service
Event Category: None
Event ID: 0
Date: 5/23/2005
Time: 4:29:21 PM
User: N/A
Computer: {omitted}
Description:

General Information
*********************************************
Additional Info:
ExceptionManager.MachineName: {omitted}
ExceptionManager.TimeStamp: 5/23/2005 4:29:21 PM
ExceptionManager.FullName: Microsoft.ApplicationBlocks.ExceptionManagement,
Version=1.0.1357.24421, Culture=neutral, PublicKeyToken=null
ExceptionManager.AppDomainName: {omitted}.traffic.output.service.exe
ExceptionManager.ThreadIdentity: {omitted}
ExceptionManager.WindowsIdentity: {omitted}

1) Exception Information
*********************************************
Exception Type: System.Runtime.InteropServices.ExternalException
ErrorCode: -2147467259
Message: A generic error occurred in GDI+.
TargetSite: Void CheckErrorStatus(Int32)
HelpLink: NULL
Source: System.Drawing

StackTrace Information
*********************************************
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawImage(Image image, Single x, Single y,
Single width, Single height)
at {omitted}.Traffic.Output.TrafficReportPrintDocument.PrintLogo(Graphics
graphics)
at
{omitted}.Traffic.Output.TrafficReportPrintDocument.OnPrintPage(PrintPageEventArgs e)
at System.Drawing.Printing.PrintDocument._OnPrintPage(PrintPageEventArgs e)
at System.Drawing.Printing.PrintController.PrintLoop(PrintDocument
document)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at {omitted}.Traffic.Output.ReportPrinter.Print(Boolean preview)
at {omitted}.Traffic.Output.Spooler.Print(PrintRequest request)
at {omitted}.Traffic.Output.Spooler.PrintLoop()

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

Thanks in advance for any help you can provide!
Patrick Gannon
 
A

Alejandro Lapeyre

Maybe too many open handles? (for windows)

Are the print jobs the same length?

Best Regards,
Alejandro Lapeyre
 
G

Guest

Alejandro,

The problem occurs even in a single-threaded scenario, so I don't see how
the problem could be too many open handles. At the end of the "using" block,
Dispose() should be implicitly called on the Metafile object, which should
close any open handles, right? The print jobs are not the same length. They
vary in size from one page to over a thousand pages, but the problem doesn't
seem to be specific to large print jobs.

The code in question executes in a Windows service, and every subsequent
print request results in an "operation completed" exception, until I restart
the service and then everything works again. There also sometimes is a
"handle is invalid" exception that occurs right after the "generic error in
GDI+" exception, but before the series of "operation completed" exceptions.

Thanks for your help!
Pat
 
G

Guest

Alejandro,

The problem occurs even in a single-threaded scenario, so I don't see how
the problem could be too many open handles. At the end of the "using" block,
Dispose() should be implicitly called on the Metafile object, which should
close any open handles, right? The print jobs are not the same length. They
vary in size from one page to over a thousand pages, but the problem doesn't
seem to be specific to large print jobs.

The code in question executes in a Windows service, and every subsequent
print request results in an "operation completed" exception, until I restart
the service and then everything works again. There also sometimes is a
"handle is invalid" exception that occurs right after the "generic error in
GDI+" exception, but before the series of "operation completed" exceptions.

Thanks for your help!
Pat
 
A

Alejandro Lapeyre

If you are using print preview the metafiles that the framework uses to
preview the pages are kept open.
Could that be the problem?
 
G

Guest

Hi Alejandro,

We don't use print previews in our application.

Thanks again for your help!
Pat
 

Ask a Question

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

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

Ask a Question

Top