Programming, technology, and CRM – from a Belgian programmer exiled to Missouri
  • rss
  • Home
  • Soft Gallery
    • autosvnbackup.sh
    • VBScript Snippets
  • Contact Me
  • Welcome

One more thought on ASP.NET Aynchronous Handlers

Nicolas Galler | February 7, 2008

OK, this is going to be really obtuse to anyone who hasn’t played with IHttpAsyncHandler, but might save me a headache when I try debugging the same problem in 2 months.

Initially I had thought that an asynchronous handler would execute “out of context”… that is, the process would be:

  1. Create context, begin request
  2. Invoke “BeginProcessRequest” from the handler
  3. End request, destroy context (INCORRECT!)
  4. Later on, when the handler finishes – return the result, but do not call End request again, since we are not on the same thread anymore

Looking back, this does not make much sense – funny how things tend to look SOOO obvious once you figured them out. But for some odd reason I thought the HttpContext would not survive accross different thread and so everything
had to happen on the initial thread.
Here is what really happens:

  1. Create context, begin request
  2. Invoke “BeginProcessRequest” from the handler
  3. Go on and do stuff while the handler works
  4. Once the handler finishes, call End request, and return the result – this could happen on a different thread than the one we started on!

One more note of interest – in the “BeginRequest” event, HttpContext will be available, but context.Handler is still null. Context.Request.Path is available, though.

Categories
Programming
Tags
ASP.NET
Comments rss
Comments rss
Trackback
Trackback

« Heap Table are Teh Suck Debug cross-domain request from local files in FireFox »

Leave a Reply

Click here to cancel reply.

Categories

  • Experiments (4)
  • Interesting (1)
  • MSCRM (1)
  • Programming (60)
  • Rant (3)
  • Saleslogix (34)
  • Tricks (8)
  • Uncategorized (30)

Post History

  • 2010
    • January (3)
    • March (3)
    • April (2)
    • August (2)
  • 2009
    • March (2)
    • April (1)
    • May (3)
    • June (3)
    • July (1)
    • September (3)
    • October (2)
    • December (5)
  • 2008
    • January (9)
    • February (4)
    • March (9)
    • April (1)
    • May (5)
    • June (8)
    • July (1)
    • August (2)
    • September (1)
    • November (1)
    • December (3)
  • 2007
    • January (3)
    • February (7)
    • March (1)
    • April (3)
    • May (6)
    • June (2)
    • July (1)
    • August (2)
    • September (5)
    • October (3)
    • November (5)
    • December (4)
  • 2006
    • January (2)
    • September (1)
    • November (3)
    • December (4)
  • 2005
    • April (1)

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox