0

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?

3
  • Sorry for answering and then unanswering. Initially thought this was a jQuery question. I don't think you are going to be able to pause your application for a second server side without it locking up the browser, but I will leave it to more qualified experts to answer that definitively. There is probably a workaround though. Sep 28, 2010 at 12:58
  • What do you mean by "the browser will collect too much data"? It seems that if the WS is returning null in most instances, this wouldn't be an issue. It seems to be me you need to handle this on the client side by cleaning up some data there if it gets too large.
    – mikeymo
    Sep 28, 2010 at 13:11
  • if i return null then there are also other data sent like headers. how can i clear resorces cache of browser with javascript?
    – Woland
    Sep 28, 2010 at 13:42

2 Answers 2

0

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.

4
  • The problem is that even if webservice returns null it will eventualy crash browser
    – Woland
    Sep 28, 2010 at 13:00
  • ather 24 hours my chrome will take over 400 mb of ram
    – Woland
    Sep 28, 2010 at 13:00
  • The second option would work though - where it stops making requests to the webservice after a while? Sep 28, 2010 at 13:01
  • well jes it will work but how will it know then when there is new data?
    – Woland
    Sep 28, 2010 at 13:02
0

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.....

4
  • 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
    Sep 28, 2010 at 13:19
  • 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
    Sep 28, 2010 at 13:26
  • 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
    Sep 28, 2010 at 13:33
  • i would be nice if there is method smthing like this Threat.ChillOut(10000);
    – Woland
    Sep 28, 2010 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.