tags:

views:

92

answers:

2

I've been told that using GDI+ from ASP.NET is dangerous and undefined.

Is that because there is no guarantee of a Device Context? Can someone explain?

What are some of the alternatives?

Here is the MSDN source:

http://msdn.microsoft.com/en-us/library/system.drawing.aspx

Edit

Windows and ASP.NET service! So perhaps a normal ASP.NET application is ok? But why?

Edit

This is not an April Fools joke, please don't treat it as such.

+1  A: 

There are numerous articles on the subject and it is possible to call this code from .NET. You need to make sure that you are disposing any objects that you create, so making use of the C# using statement is important.

The reason that System.Drawing could be problematic is that it is closely bound with how Windows does it's drawing. You should isolate the code as much as possible. With Windows Vista and later Microsoft made some changes to the service architecture which prevented interactions between the desktop and Windows services. ASP.NET is technically a service if it is hosted in IIS (most common case) so this is why Microsoft added the note. Future versions of Windows and IIS may make it more difficult or impossible to use System.Drawing from ASP.NET application.

The challenge is that some people may have misused the technology on other projects and now these people are trying to influence your use of it. One way to deal with these concerns (invalid or not as the case may be) is to create some performance and reliability metrics. Then when you start using GDI+ demonstrate the impact of it's use. The impact should be acceptable in most cases, but this will depend on what you want to do with GDI+.

BrianLy
+1  A: 

There are scalability concerns around the creation of windows handles and resources that GDI+ uses in a web environment.

Placed ASP.NET GDI+ code in a singleton so that calls are serialised and dispose of objects correctly.

I have used this technique for dynamically created images without a hitch.

James Westgate