Groups | Blog | Home
all groups > dotnet drawing api > november 2004 >

dotnet drawing api : Is GDI+ Functions Thread Safe??


Ofir
11/10/2004 4:28:54 PM
Hellow,

I have a program that draws lines,text,images on a graphics object,
from a Thread, using GDI+.

are GDI+ considered to be thread safe, or i must invoke my draw method to
the main thraed, and draw from there.

thanks,

Ofir.




Bob Powell [MVP]
11/10/2004 4:33:34 PM
The Control.CreateGraphics method is thread safe but I strongly discourage
use of it for drawing on an object because all drawing should be carried out
in the paint message cycle. The paint message will only be handled from the
UI thread so you're more or less obliged to do all of your painting in that
thread.

The methods of the Graphics object are generally not threadsafe and can
result in exceptions if two threads attempt to use the same Graphics object.

You can use threads to change the positions of objects in a game or to
update data which is then drawn by the UI thread in the normal paint cycle
but generally I would say that actually doing the drawing from several
threads is a bad idea.

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

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

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml






[quoted text, click to view]

AddThis Social Bookmark Button