0

I have an event that I'm firing every 5 seconds to check if a file has finished processing.

I'm doing the following:

if (InSuppArray(item.Id) == false && item.Status() == "Queue") {
    var t = setTimeout(function () { checkQueuedSupp(item.OrderId) }, 5000);
    suppIds.push({ Id: item.OrderId, TimerId: t });
}

Basically, multiple files can be uploaded so this created an array of timers and kills them as the files completes.

This works great in Firefox and Chrome, but the timer only fires one time in Internet Explorer.

Is there a better way to do this? I searched around and found some issues with IE and setTimeout but most of those were alluding to the fact that it just never works in IE, which mine at least fires once.

4

2 回答 2

0

1) 正在为第一次迭代工作吗?是的,您的代码工作正常。

2)如果重复是您的问题,请检查以下内容:

setTimeout不是重复的方法。而是使用setInterval.

if (InSuppArray(item.Id) == false && item.Status() == "Queue") {
    var t = setInterval(function () { checkQueuedSupp(item.OrderId) }, 5000);
    suppIds.push({ Id: item.OrderId, TimerId: t });
}

要使其setTimeout具有重复性,请尝试使其具有recursive.

于 2013-08-30T05:21:50.303 回答
0

setTimeout 是延迟执行函数,而不是重复执行。您想要的是 setInterval ,它将在您指定的每个时间间隔内执行您的函数。

于 2013-08-30T05:14:42.110 回答