SetInterval called function crashes - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

SetInterval called function crashes

bsaucerbsaucer Posts: 40Member
I have an web app with some javascript functions. When you click a button it starts two "SetInterval" timers going, each calling a separate function. It calls one function first, and then it crashes. I get this error while debugging the page with VB.Net:

"Microsoft Javascript Error. Object Expected [Break][Continue]"

When I click "Continue" another error pops up:

"There is no source code available for the current location. [OK]"

When I step through the code, it crashes after exiting one of the timer functions. It's as if it has no place to go when it returns to caller.

Here's the script code stripped down to the bare ninimum (still crashes!)


[code]
// JScript File

var tmr1, tmr2



function HitScreen()
{
var a=0
} // crashers when it exits here.

function reCallServer()
{
var b=0
}



function btnStart_click() // This executes when I click the "Start" button
{
if (tmr1 == null)
{
var delay = parseInt(document.getElementById("txtRate").value)
tmr1 = setInterval("HitScreen()", delay)
}

if (tmr2 == null)
{
tmr2 = setInterval("ReCallServer()", 100)
}

return false
}

function btnStop_click()
{
if (tmr2 != null)
{
clearInterval(tmr2)
tmr2 = null
}
return false
}
[/code]
The web page is actually an ASP.Net page with AJAX controls: A Script manager, and some slider controls, along with some buttons, text boxes, div boxes, etc. I don't know if any of that is a factor. The same errors occur when I debug with firefox.

Comments

  • CyGuyCyGuy Posts: 312Member
    : I have an web app with some javascript functions. When you click a
    : button it starts two "SetInterval" timers going, each calling a
    : separate function. It calls one function first, and then it crashes.
    : I get this error while debugging the page with VB.Net:
    :
    : "Microsoft Javascript Error. Object Expected [Break][Continue]"
    :
    : When I click "Continue" another error pops up:
    :
    : "There is no source code available for the current location. [OK]"
    :
    : When I step through the code, it crashes after exiting one of the
    : timer functions. It's as if it has no place to go when it returns to
    : caller.
    :
    : Here's the script code stripped down to the bare ninimum (still
    : crashes!)
    :
    : [red]need ;semicolon[/red]
    : [code]:
    : // JScript File
    :
    : var tmr1, tmr2[red]<-here[/red]
    :
    :
    :
    : function HitScreen()
    : {
    : var a=0 [red]<-here[/red]
    : } // crashers when it exits here.
    :
    : function reCallServer()
    : {
    : var b=0 [red]<-here[/red]
    : }
    :
    :
    :
    : function btnStart_click() // This executes when I click the "Start" button
    : {
    : if (tmr1 == null)
    : {
    : var delay = parseInt(document.getElementById("txtRate").value)[red]<-here[/red]
    : tmr1 = setInterval("HitScreen()", delay)[red]<-here[/red]
    : }
    :
    : if (tmr2 == null)
    : {
    : tmr2 = setInterval("ReCallServer()", 100)[red]<-here[/red][green]don't ya me "reCallServer();"[/green][red]Object()[/red]
    : }
    :
    : return false[red]<-here[/red]
    : }
    :
    : function btnStop_click()
    : {
    : if (tmr2 != null)
    : {
    : clearInterval(tmr2)[red]<-here[/red]
    : tmr2 = null[red]<-here[/red]
    : }
    : return false[red]<-here[/red]
    : }
    : [/code]:
    : The web page is actually an ASP.Net page with AJAX controls: A
    : Script manager, and some slider controls, along with some buttons,
    : text boxes, div boxes, etc. I don't know if any of that is a factor.
    : The same errors occur when I debug with firefox.
    :
    Also not sure about txtRate element, but the call to the ReCallServer is probably the culprate:)
  • bsaucerbsaucer Posts: 40Member
    Aren't semicolons optional in javascript?

    : I have an web app with some javascript functions. When you click a
    : button it starts two "SetInterval" timers going, each calling a
    : separate function. It calls one function first, and then it crashes.
    : I get this error while debugging the page with VB.Net:
    :
    : "Microsoft Javascript Error. Object Expected [Break][Continue]"
    :
    : When I click "Continue" another error pops up:
    :
    : "There is no source code available for the current location. [OK]"
    :
    : When I step through the code, it crashes after exiting one of the
    : timer functions. It's as if it has no place to go when it returns to
    : caller.
    :
    : Here's the script code stripped down to the bare ninimum (still
    : crashes!)
    :
    :
    : [code]:
    : // JScript File
    :
    : var tmr1, tmr2
    :
    :
    :
    : function HitScreen()
    : {
    : var a=0
    : } // crashers when it exits here.
    :
    : function reCallServer()
    : {
    : var b=0
    : }
    :
    :
    :
    : function btnStart_click() // This executes when I click the "Start" button
    : {
    : if (tmr1 == null)
    : {
    : var delay = parseInt(document.getElementById("txtRate").value)
    : tmr1 = setInterval("HitScreen()", delay)
    : }
    :
    : if (tmr2 == null)
    : {
    : tmr2 = setInterval("ReCallServer()", 100)
    : }
    :
    : return false
    : }
    :
    : function btnStop_click()
    : {
    : if (tmr2 != null)
    : {
    : clearInterval(tmr2)
    : tmr2 = null
    : }
    : return false
    : }
    : [/code]:
    : The web page is actually an ASP.Net page with AJAX controls: A
    : Script manager, and some slider controls, along with some buttons,
    : text boxes, div boxes, etc. I don't know if any of that is a factor.
    : The same errors occur when I debug with firefox.
    :
  • CyGuyCyGuy Posts: 312Member
    That would be news to me. Did this fix your Problem?

    : Aren't semicolons optional in javascript?
    :
    : : I have an web app with some javascript functions. When you click a
    : : button it starts two "SetInterval" timers going, each calling a
    : : separate function. It calls one function first, and then it crashes.
    : : I get this error while debugging the page with VB.Net:
    : :
    : : "Microsoft Javascript Error. Object Expected [Break][Continue]"
    : :
    : : When I click "Continue" another error pops up:
    : :
    : : "There is no source code available for the current location. [OK]"
    : :
    : : When I step through the code, it crashes after exiting one of the
    : : timer functions. It's as if it has no place to go when it returns to
    : : caller.
    : :
    : : Here's the script code stripped down to the bare ninimum (still
    : : crashes!)
    : :
    : :
    : : [code]: :
    : : // JScript File
    : :
    : : var tmr1, tmr2
    : :
    : :
    : :
    : : function HitScreen()
    : : {
    : : var a=0
    : : } // crashers when it exits here.
    : :
    : : function reCallServer()
    : : {
    : : var b=0
    : : }
    : :
    : :
    : :
    : : function btnStart_click() // This executes when I click the "Start" button
    : : {
    : : if (tmr1 == null)
    : : {
    : : var delay = parseInt(document.getElementById("txtRate").value)
    : : tmr1 = setInterval("HitScreen()", delay)
    : : }
    : :
    : : if (tmr2 == null)
    : : {
    : : tmr2 = setInterval("ReCallServer()", 100)
    : : }
    : :
    : : return false
    : : }
    : :
    : : function btnStop_click()
    : : {
    : : if (tmr2 != null)
    : : {
    : : clearInterval(tmr2)
    : : tmr2 = null
    : : }
    : : return false
    : : }
    : : [/code]: :
    : : The web page is actually an ASP.Net page with AJAX controls: A
    : : Script manager, and some slider controls, along with some buttons,
    : : text boxes, div boxes, etc. I don't know if any of that is a factor.
    : : The same errors occur when I debug with firefox.
    : :
    :
  • bsaucerbsaucer Posts: 40Member
    I ended up removing the secont timer (SetInterval) and used one Setinterval and two counting loops. That fixed the crashes (without semicolons), but the response is slow.

    I have one counter set to work at 10 msec, and another one set to whatever the control is set for (1-101 msec, tested at 100 msec). The 10 msec counter polls the server for some data into an array, while the other one processes the data locally. The dalay value (and other parameters) are sent to the server on each call, and it sends back enough data depending on how much time has lapsed since last time.

    How long does it normally take the server to reply on asynchronous callbacks?

    : That would be news to me. Did this fix your Problem?
    :
    : : Aren't semicolons optional in javascript?
    : :
  • CyGuyCyGuy Posts: 312Member
    To this point, I haven't done a lot of server side programming... can't get a good static line.
    [i]
    There are a lot of variables involved here
    [/i]
    Even if you get a stable network in a controlled environment. What priority is the browser running on? and your network services??
    [green]WHAT you;see_is_what=you.get;[/green]
    -Russ aka DangeRuss
Sign In or Register to comment.