-1

I am using the ASP.NET GeneratedImage control (http://weblogs.asp.net/craigshoemaker/archive/2008/08/19/new-asp-net-generated-image-control.aspx)

The image handler seems to receive multiple requests at once from the same client and then the application_error is called multiple times at once (because there are multiple images on the page). Is this correct? For example, if a web page contains three images, then the Image Handler is called three times almost all at once (after the page is loaded). This is happening when I step through the code.

My question isn't about why I am receiving the error, but why the image handler seems to receive multiple requests for images at once.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
w0051977
  • 15,099
  • 32
  • 152
  • 329

2 Answers2

0

The handler will be called as many times as its URL is referenced in the HTML.

When a browser parses an HTML file, it will request each and every external resource referenced in the HTML (so CSS, JS, images etc...).

Most modern browsers have several threads per page that will download these in parallel. So, the handler will be called by the browser several times - once per image.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • That makes sense. I put a breakpoint in my application error event (on the first line) and started stepping through the code. On the third line the debugger stepped back to the beginning of the function and then went forward four lines. It seems to be a bit random really. I think that the application_error starts processing for image one and then begins processing for image two and then finishes processing for image 1 and finishes processing for image 2. Does this sound correct? Thanks again. – w0051977 Sep 09 '11 at 19:50
  • @Ian - sounds likely. Try with a _single_ image, so you can step through without confusion. Alternatively, I believe VS2010 has support for multiple threads debugging if needed. – Oded Sep 09 '11 at 19:51
  • I have not implemented threading into my application explicitly, but I suppose that parts of the .NET API use Threading. Is it possible to have part of your application Threaded and part of your application unthreaded? – w0051977 Sep 09 '11 at 20:49
  • @Ian - yes, it is. Not sure you need it though. ASP.NET and IIS automatically handle most of these issues for you (parallel requests, that is). – Oded Sep 09 '11 at 20:50
  • Do you know where this is documented. I found this example explaining how pages are requested in parallel:http://stackoverflow.com/questions/3988523/asp-net-how-parallel-requests-are-processed, however I cannot find anything about images processed in parallel. – w0051977 Sep 09 '11 at 20:57
  • @Ian - IIS serves _requests_. These can be for pages _or_ images _or_ anything. – Oded Sep 09 '11 at 20:59
0

Any ASP.NET handler may be called on multiple threads, so yes, it may be called multiple times "at the same time".

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • That makes sense. I put a breakpoint in my application error event (on the first line) and started stepping through the code. On the third line the debugger stepped back to the beginning of the function and then went forward four lines. It seems to be a bit random really. I think that the application_error starts processing for image one and then begins processing for image two and then finishes processing for image 1 and finishes processing for image 2. Does this sound correct? Thanks again. – w0051977 Sep 09 '11 at 19:47