I have an ActiveX object (who source code I have) running in a browser (IE). The ActiveX object has a UI, which raises events. I want to respond to those events in the browser.
I don't want to invoke JavaScript functions from the ActiveX object events: and therefore, instead, I want the JavaScript to poll a method of the ActiveX object (to say, "do you have any events to report?").
I'll do that with code like this:
function findActiveXObject() {
return document.getElementById('MyActiveXObject');
}
function startPolling() {
setTimeout('pollForEvents()', 100);
}
function pollForEvents() {
var activeXObject = findActiveXObject();
var eventMsg = activeXObject.PollForEvent();
if (eventMsg != null)
{
//do something with the event
alert(eventMsg);
}
//poll again soon
startPolling();
}
What's a good polling interval?
I guess, though I'm not sure, that the amount of work is small: it's just calling a method of an ActiveX object, which either returns an already cached string or returns null.
I'd like to poll frequently: so that it looks like the browser (actually the JavaScript) responds promptly to UI events in the ActiveX object.
Is 100 msec too small? How about 50 msec?
With a 100 msec interval I see only a 1% CPU utilization in the browser: but that's just on my machine. What about in general (desktop mchines running IE)?
If this were a native thread I wouldn't worry about waking it up every 50 msec, but I have little experience with running JavaScript in IE.