473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Trouble of GDI+ generic error!

Hi everybody,

I'm facing a serious trouble relating to GDI+ generic error. The error
message is "A Generic error occured in GDI+" and the following information
is stored in Excepton object:
System.Drawing.Graphics.CheckErrorStatus(Int32 status)
System.Drawing.Graphics.DrawString(String s, Font font, Brush brush,
RectangleF layoutRectangle, StringFormat format)
System.Drawing.Graphics.DrawString(String s, Font font, Brush brush,
PointF point, StringFormat format)

In my application, I use DrawString to print text on printer. This is a POS
application in retail store and one receipt is printed every minute in rush
hours. The symptom reported by user is the program stop response or no
receipt is printed after 3 or 4 hours operation during rush hours. The
above error message is logged by my appliction. After reboot the machine,
it works normally again for another few hours.

I suspect the problem is caused by memory corruption but no idea how to
trace to source. The suspects are:
1. my code
2. GDI+ / .NET Framework
3. hardware (e.g. insufficient RAM)

I've also tried to add some GC.Collect() code in my code but there's no
improvement at all.

Here is the hardware / software configuration to run my application:
1. Intel Celeron 2G with 512MB
2. Star TSP 700 printer
3. Windows XP Professional with SP2 and latest patches
4. .NET Framework 2.0
5. SQL Server 2000 Desktop Edition with latest patches
6. Application compiled by VB.NET 2005

Would anybody have any idea how I can trace the source of this problem?
Thanks a lot for your attention and kindly advice!

Regards,
James Wong
Mar 20 '07 #1
14 4082
Hi James,

From your description, you're encountering the following error:

"A Generic error occured in GDI+......."

in a winform application which print outo some string data into printer,
correct?

As for the "A Generic error occured in GDI+", it does be a very generic
exception that will sometimes occur in graphics application. I'm not sure
whether your applciation's code logic is very complex and contains many
other codelogic (not related to the GDI+ printing)? if so, I would suggest
you try creating a simplified project that dedicate the GDI+ processing to
see whether you can reproduce the issue.

For memory specific issue, a commom diagnostic means is using the
performance counter(process memory) to montior the managed and unmanaged
memory usage of your application's running process. You can check whether
there is particular memory pressure(at unmanaged or managed memory ...).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 20 '07 #2
Hi Steven,

Thanks for your response!

Yes, I got this error while printing something to printer in WinForm
application. However, this problem does not occurs everytime when I print,
so it's not easy to reproduce. What I can ensure is that if the program
runs for 3 or 4 hours (maybe around 200+ receipts are printed), this problem
may happen. After restarting the program (no need to reboot), it resumes to
normal for another few hours before the problem occurs again.

For the performance count, I found it may be useful for me to monitor the
memory status. However, there are so many counter names under memory and
process categories, will you suggest me to focus some of them in my
application?

Thanks again for your advice!

Regards,
James Wong

"Steven Cheng[MSFT]" <st*****@online.microsoft.com¼¶¼g©ó¶l¥ó·s»D:6v**** **********@TK2MSFTNGHUB02.phx.gbl...
Hi James,

From your description, you're encountering the following error:

"A Generic error occured in GDI+......."

in a winform application which print outo some string data into printer,
correct?

As for the "A Generic error occured in GDI+", it does be a very generic
exception that will sometimes occur in graphics application. I'm not sure
whether your applciation's code logic is very complex and contains many
other codelogic (not related to the GDI+ printing)? if so, I would suggest
you try creating a simplified project that dedicate the GDI+ processing to
see whether you can reproduce the issue.

For memory specific issue, a commom diagnostic means is using the
performance counter(process memory) to montior the managed and unmanaged
memory usage of your application's running process. You can check whether
there is particular memory pressure(at unmanaged or managed memory ...).

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Mar 20 '07 #3
Thanks for your reply James,

For memory specific performance counters, the following twos are very
useful:

category counter name

Process Private Bytes
NET CLR Memory #Bytes in all Heaps

"Private Bytes" counter(of Process category) is used to inspect the
physical private bytes consumed by your application process

"#Bytes in all Heaps" counter(of .NET CLR Memory category) is used to check
all the bytes in .NET managed heap

Here is a good msdn reference introducing production debugging of .NET
application

#Production Debugging for .NET Framework Applications
http://msdn2.microsoft.com/en-us/library/ms954591.aspx

And normally, memory issue in .net framework application will possibly be
caused by following things:

Caching/Session state
Large amount of sites
Debug mode
XSLT Transformations/XML Serialization
Pinning
Binary Formatter
Large Object Heap
COM objects with Events
Blocked Finalizer

Hope this also helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 21 '07 #4
Hi Steven,

Thanks again for your reply!

I'll try to figure out what's happen on my application.

Regards,
James Wong

"Steven Cheng[MSFT]" <st*****@online.microsoft.com¼¶¼g©ó¶l¥ó·s»D:kk**** **********@TK2MSFTNGHUB02.phx.gbl...
Thanks for your reply James,

For memory specific performance counters, the following twos are very
useful:

category counter name

Process Private Bytes
NET CLR Memory #Bytes in all Heaps

"Private Bytes" counter(of Process category) is used to inspect the
physical private bytes consumed by your application process

"#Bytes in all Heaps" counter(of .NET CLR Memory category) is used to
check
all the bytes in .NET managed heap

Here is a good msdn reference introducing production debugging of .NET
application

#Production Debugging for .NET Framework Applications
http://msdn2.microsoft.com/en-us/library/ms954591.aspx

And normally, memory issue in .net framework application will possibly be
caused by following things:

Caching/Session state
Large amount of sites
Debug mode
XSLT Transformations/XML Serialization
Pinning
Binary Formatter
Large Object Heap
COM objects with Events
Blocked Finalizer

Hope this also helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.



Mar 21 '07 #5
Just a wild guess, but are you sure you dispose of the brush and font used to
draw the string after each call to your routine.
--
Dennis in Houston
"James Wong" wrote:
Hi Steven,

Thanks again for your reply!

I'll try to figure out what's happen on my application.

Regards,
James Wong

"Steven Cheng[MSFT]" <st*****@online.microsoft.com¼¶¼g©ó¶l¥ó·s »D:kk**************@TK2MSFTNGHUB02.phx.gbl...
Thanks for your reply James,

For memory specific performance counters, the following twos are very
useful:

category counter name

Process Private Bytes
NET CLR Memory #Bytes in all Heaps

"Private Bytes" counter(of Process category) is used to inspect the
physical private bytes consumed by your application process

"#Bytes in all Heaps" counter(of .NET CLR Memory category) is used to
check
all the bytes in .NET managed heap

Here is a good msdn reference introducing production debugging of .NET
application

#Production Debugging for .NET Framework Applications
http://msdn2.microsoft.com/en-us/library/ms954591.aspx

And normally, memory issue in .net framework application will possibly be
caused by following things:

Caching/Session state
Large amount of sites
Debug mode
XSLT Transformations/XML Serialization
Pinning
Binary Formatter
Large Object Heap
COM objects with Events
Blocked Finalizer

Hope this also helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.



Mar 22 '07 #6
Hi James,

If you get any progress or if there is anything else we can help you,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 22 '07 #7
Hi Dennis,

Thanks for your hints. I don't dispose brush or font after drawing. Do you
mean I have to do so and it may be the cirtical point to my problem?
Anyway, I'll try to dispose them and see the result.

Regards,
James Wong

"Dennis" <De****@discussions.microsoft.com¼¶¼g©ó¶l¥ó·s»D:B5 **********************************@microsoft.com.. .
Just a wild guess, but are you sure you dispose of the brush and font used
to
draw the string after each call to your routine.
--
Dennis in Houston

Mar 23 '07 #8
Hi James,

For those graphics objects such as Brush, Bitmap, Font... they will hold
win32 unmanaged resource handle, thus, whenever you have used large number
of such objects and haven't explcitly dispose them at ealiear time, they'll
hold significant operating system resource(GDI handles). Therefore, you're
recommended to explicitly dispose them after finishing use them.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 23 '07 #9
Hi Steven,

Thanks for your information!

By the way, I've got another problem related to .NET framework and I've
posted it with subject ".NET runtime error" in newsgroup .dotnet.framework.
However, there is no response there for over two days. Would you have a
look and give me some hints? Thanks a lot!

Regards,
James Wong

"Steven Cheng[MSFT]" <st*****@online.microsoft.com¼¶¼g©ó¶l¥ó·s»D:Nc**** ************@TK2MSFTNGHUB02.phx.gbl...
Hi James,

For those graphics objects such as Brush, Bitmap, Font... they will hold
win32 unmanaged resource handle, thus, whenever you have used large number
of such objects and haven't explcitly dispose them at ealiear time,
they'll
hold significant operating system resource(GDI handles). Therefore, you're
recommended to explicitly dispose them after finishing use them.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Mar 26 '07 #10
Hi Steven,

I still have something not quite sure about when I should call Dispose. The
followings are some pseudo code to show my question:
Public Shared Sub A()

Dim objFont As Font

objFont = New Font (...)

Call B (objFont)

' I should call objFont.Dispose here before end of the sub, right?

Call B (New Font (...))

' if I call sub B in this way (without creating a variable), how can I
call Dispose?

End Sub
Public Shared Sub B(ByVal objFont As Font)

'... do something here with objFont

' Do I need to call objFont.Dispose here before end of the sub?

' I'm not quite sure that objFont in this sub is an independent instance
from objFont in Sub A

End Sub
And you may right that I use a lot of font objects to print and this may be
the major cause of my problem.

Thanks again for your help!

Regards,
James Wong
"Steven Cheng[MSFT]" <st*****@online.microsoft.com¼¶¼g©ó¶l¥ó·s»D:Nc**** ************@TK2MSFTNGHUB02.phx.gbl...
Hi James,

For those graphics objects such as Brush, Bitmap, Font... they will hold
win32 unmanaged resource handle, thus, whenever you have used large number
of such objects and haven't explcitly dispose them at ealiear time,
they'll
hold significant operating system resource(GDI handles). Therefore, you're
recommended to explicitly dispose them after finishing use them.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Mar 26 '07 #11
Thanks for your reply james,

Regardingon the those managed GDI+ objects(such as Pen, Brush, Font ....),
you're recommended to dispose it rigth after you've finished using it (in a
certain GDI+ function call such as DrawXXX). Generally, you can consider
put the object disposing code at the end of the certain function which
perform a GDI+ task.

In addition, here is a GDI+ FAQ article about when to dispose object:

#Disposing of GDI+ resources
http://www.bobpowell.net/disposing_of_resources.htm

and there are many other useful faq articles on GDI+ there:

http://www.bobpowell.net/faqmain.htm

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 28 '07 #12
Hi Steven,

Thanks for your information! I've modified my code and the situation seems
to be better than before. I'm still monitoring the performance and behavior
of my new style coding. I'll let you know if this solve my problem
eventually.

Regards,
James Wong

"Steven Cheng[MSFT]" <st*****@online.microsoft.com¼¶¼g©ó¶l¥ó·s»D:9s**** **********@TK2MSFTNGHUB02.phx.gbl...
Thanks for your reply james,

Regardingon the those managed GDI+ objects(such as Pen, Brush, Font ....),
you're recommended to dispose it rigth after you've finished using it (in
a
certain GDI+ function call such as DrawXXX). Generally, you can consider
put the object disposing code at the end of the certain function which
perform a GDI+ task.

In addition, here is a GDI+ FAQ article about when to dispose object:

#Disposing of GDI+ resources
http://www.bobpowell.net/disposing_of_resources.htm

and there are many other useful faq articles on GDI+ there:

http://www.bobpowell.net/faqmain.htm

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no
rights.

Mar 29 '07 #13
Hi James,

Glad that you've got progress on this.

Sure, if there is anything else we can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Mar 30 '07 #14
Hi James,

Have you resolved the issue or still anything need our help?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 3 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
3
by: cdj | last post by:
Hi all, I've got a picturebox on a form, and a save button. When I go to save, the app craps out with the following error: ================== An unhandled exception of type...
5
by: Pohihihi | last post by:
I am getting a generic GDI+ error on following code. Basically it is trying to capture screen image and save in a file. Is there a way to find more details on this error? Thanks for the help. ...
2
by: Alphonse Giambrone | last post by:
I am currently reading 'Programming The Web with Visual Basic .NET' and have so far found it to be excellent. Downloaded all the code from Apress and working in chapter 4, I get the error shown...
13
by: lgbjr | last post by:
Hello All, I have some pictureboxes on a VB.NET form that are linked to an AccessDB. If the user wishes to open or edit an image, I need to save the image in the picturebox to a temp file, then...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
0
by: manini | last post by:
Hello Everyone I m getting the generic GDI + error,Please help me to resolve this error ************** Exception Text ************** System.Runtime.InteropServices.ExternalException: A generic...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.