Home All Groups Group Topic Archive Search About

Callback to Multiple Requests

Author
15 May 2006 6:21 PM
Chris
I have an ASP.Net 2.0 web app that performs an HttpWebRequest and
updates the database as needed (when it's not up to date).

I need to ensure that the request and update is only performed once (it
performs inserts) and don't want to lock multiple request threads while
this is happening as most requests to the site don't rely on the
update. I figure that the first request that requires the resource can
fire off an async request and register a callback for the response.
However, what happens if a another request comes along requiring the
same resource before the request is completed it needs to just wait for
the same 'callback event' but should then carry on with it's own
PreRender etc (assuming I use Page.RegisterAsyncTask).

I want to place the request handling in a singleton that is responsible
for ensuring that the request happens only once. I'm trying to figure
out the best way to do this. Do I need to expose an IAsyncResult method
from my singleton that returns the result of the BeginRequest, so the
Page can add a delegate wrapper around it? How can I kick off any
further waiting requests when the request returns without resorting to
polling the singleton? I figure the other threads could somehow
register as an observer with the singleton, passing their own callback
delegate but I'm having trouble figuring out the details.

Has anyone done something similar before?

AddThis Social Bookmark Button