|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Handling requests that have a long response timeI have a request to the server that could take upto 10 mins to come back
and display the results. I want to either a) Redirect to a new "Please wait" page till the processing is done, then redirect back to the results page , or b) Display a "Please wait" message on the same page that sends the request to the server and refresh the page to display the results. I know websites like orbitz and travelocity do this. Any idea how I would accomplish this? Thanks, -SJ. "SJ" wrote ...
>I have a request to the server that could take upto 10 mins to come back Hi SJ,> and display the results. > I want to either > a) Redirect to a new "Please wait" page till the processing is done, then > redirect back to the results page , or > b) Display a "Please wait" message on the same page that sends the request > to the server and refresh the page to display the results. > I know websites like orbitz and travelocity do this. > > Any idea how I would accomplish this? I'm not sure if this is the "best" approach - but it is certain "an" approach :o) Presumably whatever you are 'triggering' is database driven? Hencing the processing time? My thought was that perhaps if you were able to ascertain an ID of sorts, you could keep redirecting to the same page every 10 seconds or something sending the ID in the form or querystring, and, if this page receives an ID then it checks the current "state" of the processing, until it comes back and says "I'm done" it keeps refreshing every 10 seconds. The page could easily have an animated .gif or something on it to indicate that something is still happening. As I said, probably not the best approach, but an approach none the less. I've fired things off using threading before to ensure they complete, but I've never (yet) had the need to wait around to see what the outcome was on the same request. I don't feel I've been much help - sorry.. Rob Rob,
Don't sell your idea short. I think it's a valid one. I only see a couple of things I would recommend in addition. The "I'm done" state could certainly be represented by some Status field. I would refresh the current page at a larger interval than 10 seconds if the operation could take 10 minutes. Set the refresh to occur 5-10 seconds before the script timeout (i.e. Timeout = 90 seconds, refresh the page every 80 seconds). Perhaps, use a postback instead of a refresh with a querystring variable. I only say this to make things harder for tampering users or hackers. You could emit the JavaScript with a postback reference similar to the following: //------------------------------------------------------- private int TaskID { get { object Value = ViewState["TaskID"]; if (Value == null) return 0; else return (int)Value; } set { ViewState["TaskID"] = value; } } private void Page_Load(object sender, System.EventArgs e) { if (Page.IsPostBack) { string JSFunction = GetPostBackEventReference(this); RegisterStartupScript("Refresh", "<script language=\"JavaScript\">window.setTimeout(\"" + JSFunction + "\", " + ((Server.ScriptTimeout - 10) * 1000).ToString() + "</script>"); } } private void Button1_Click(object sender, System.EventArgs e) { // Retrieve some sort of task ID just before beginning the task. this.TaskID = GetNewTaskID(); // Begin the very long procedure here. ... } //------------------------------------------------------- I really like the idea of an animated GIF image as well. Regards, Matt "SJ" <mymai***@sbcglobal.net> wrote in news:lLFmf.35601$Zv5.128 @newssvr25.news.prodigy.net:> I have a request to the server that could take upto 10 mins to come back What is processing the request?> and display the results. Database? Query? Service? If it's extreme long running, you may want to look at Message Queues... which will let you monitor the status of a pending request without tying up too many resources. -- Stan Kee (spamhoneypot@rogers.com) |
|||||||||||||||||||||||