SetTimeout not triggering as expected

D

DJ Farkus

I'm got some Javascript which is designed to monitor the progress of a
process being performed by an ActiveX control. The problem is that my
timeout function is not being triggered until my ActiveX control has
completely finished it's processing.

Here's a simplification of my problem:

<script language="JavaScript">
var progressTimer;

function progress_settimer() {
progressTimer = setTimeout('progress_update()', 500);
}

function progress_clearttimer() {
clearTimeout(progressTimer);
}

function progress_update() {
<!-- do some work here -->
<!-- restart the timeout -->
progress_settimer()
}
</script>

<script for="AXControl" event="ProcessStart()" language="JavaScript">
<!-- set up a timeout to monitor progress -->
progress_settimer();
</script>

<script for="AXControl" event="ProcessFinished()"
language="JavaScript">
<!-- clear the progress timeout -->
progress_clearttimer();
</script>

.. . . .

<OBJECT ID="AXControl"
CLASSID="CLSID:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX">
</OBJECT>

Here's a summary of the expected sequence:
- AXControl fires the ProcessStart event
- Javascript handles the event, sets up a timeout to monitor progress
- AXControl begins it's processing
- (many) timeout function "progress_update" is triggered, timeout is
restarted
- AXControl finishes it's processing
- AXControl fires the ProcessFinished event
- Javascript handles the event, clears the timeout

The AXControl fires off the ProcessStart event, and my Javascript
handles the event by setting up the timeout event. The
progress_update() function should be called every 500 msecs until the
AXControl fires off the ProcessFinished event. The AXControl event
handlers are being properly triggered and run as expected.

But in the intervening time (around 10 seconds), my progress_update
function is never called. I even put some Sleep calls in my ActiveX
control to ensure that it takes a while to do it's processing and is
not hogging the processor (a long shot at best).

Even stranger, if I comment out the call to progress_cleartimer() in
the ProcessFinished event handler, my progress_update() function IS
eventually called, but only after the ProcessFinished event a fired by
the AXControl. During the 10 seconds of processing, the progress_update
function is never called.

In other words:
Here's a summary of the expected sequence:
- AXControl fires the ProcessStart event
- Javascript handles the event, sets up a timeout to monitor progress
- AXControl begins it's processing
- (10 seconds)
- AXControl finishes it's processing
- AXControl fires the ProcessFinished event
- Javascript handles the event (does NOT clear timeout)
- "progress_update" is FINALLY triggered for the first time

Is this a scoping issue? Is the setTimeout target function not being
triggered because I set the timeout in the scope of an OBJECT event
handler?

Help me out if you can. I'm stumped...

Thanks,
DJ Farkus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,069
Latest member
SimplyleanKetoReviews

Latest Threads

Top