Vishful thinking…

System.Drawing.Imaging Namespace

Posted in Uncategorized by viswaug on September 11, 2008

I was really taken aback today when I read that Microsoft does not support the use of the “System.Drawing.Imaging” Namespace within a windows or ASP.NET service. I have never had a problem with it when I have used it before and don’t expect to have a problem with it. But it is surprising that Microsoft doesn’t support it. Just thought some others might have the same reaction to it as I did…


2 Responses

Subscribe to comments with RSS.

  1. Morten said, on September 11, 2008 at 8:08 pm

    The reason is that it internally uses unmanaged GDI. As I understand it, a lot of the objects in the System.Drawing namespace (NOT only the Imaging namespace!) uses up device contexts, and unfortunately Windows has a very hard limit on those (it can even bring down the server if you use up all of them).
    Make sure that you explicitly call dispose on your System.Drawing.* objects as soon as possible, and you should be fine. Generally the shorter lifespan they have, the less likely you are to hit this limit.
    Technically this is not only a problem with ASP.NET only, but it’s much more likely to hit the limit with many users and a garbage collector that struggles to keep up with with disposing your objects.
    Just a side note: It’s not all objects that have this problem. For instance System.Drawing.Color is just fine to use (generally if it doesn’t implement IDisposable you should be fine).

  2. viswaug said, on September 11, 2008 at 9:22 pm

    Hi Morten,

    Thank you for the insights into the System.Drawing namespace. Do you know if using the WPF Canvas to make your images in 3.5 makes it more stable? (with WPF being mostly managed code)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: