tags:

views:

47

answers:

2

I have a webpage what asks through jQuery json data from webservice after every 1 second. If there is no data then webservice returns null.

The problem is that if client is on site over 24 hours then the browser will collect too much data and will crash. So I decided to set timeout to 60000 in jQuery ajax so it will wait for data and on server side I am trying to to somthing like this:

while(true)
{
  if(thereIsData){
     System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
     new System.Web.Script.Serialization.JavaScriptSerializer();
     string sJSON = oSerializer.Serialize(ActionList);
     Context.Response.Output.Write(sJSON);
     return;
  }
 Thread.Sleep(1000);
}

But if I use Thread.Sleep then it will lock entire page. I have tried threading EventWaitHandle and same result entire page is locked until there is data. I also tried creating other webservice but same results. Is there any way that I can do this?

A: 

Why don't you just count up the number of times it has requested the data, and when it has requested more than 1000 items, for example, then return null after that point.

Or get the code making the webservice call to do something similar and only call it a maximum number of times before it stops trying.

Fiona Holder
The problem is that even if webservice returns null it will eventualy crash browser
Woland
ather 24 hours my chrome will take over 400 mb of ram
Woland
The second option would work though - where it stops making requests to the webservice after a while?
Fiona Holder
well jes it will work but how will it know then when there is new data?
Woland
A: 

It sounds similar to a "chat" like application. One of the algorithms for handling this would be to have a progressively "sliding scale" of polling such as:

1) If no updates have come back in n-minutes, bump polling rate up to three seconds 2) If no updates for another n-minutes, bump poll rate up to 5 seconds, then 10 etc 3) When you "have activity (non null return value), slide it back down to 1 second polls and repeat steps 1 and 2.....

mikeymo
Jes it is similar to chat app. I have though about this solution. But back to the question, is there anyway that i can pause webservice threat without locking it to other requests, so that i can use this wait for data solution described above?
Woland
Not that I'm aware of..... javascript is single threaded so when you make the http request, it's going to wait for a response (block the client). What about if after n number of requests (or some time period) you redirect back into your page (Response.Redirect type of action) so the browser is forced to do a total refresh on the page....this might flush some of the resource usage that creeps up over time.
mikeymo
well jess i have do to this then if there is no other solution. I have to save clients not saved data first and then reload it, its lot of work.;(
Woland
i would be nice if there is method smthing like this Threat.ChillOut(10000);
Woland