Is it possible to sleep in JScript executed by C# MSScriptControl.ScriptControlClass?

562 Views Asked by At

I'd like to be able to sleep in a JScript executed by C# MSScriptControl.ScriptControlClass. I thought that maybe the WScript.Sleep() function might be available, but I'm getting a "WScript is undefined" error message when trying that. I'm new to scripting outside of a web browser. I thought that MSScriptControl.ScriptControlClass and Windows Script Host might be related, but maybe they're not. If there isn't a sleep function that is available to the script, then what's the next best thing?

2

There are 2 best solutions below

0
On BEST ANSWER

There is no sleep function within javascript, maybe you can write a COM executable with implemented sleep-function or find one, which already has this function.

0
On

The below javascript works fine for me to sleep within an MsScriptControl routine:

function sleepFor( sleepDuration ){
    var now = new Date().getTime();
    while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } 
}

sleepFor(10000); //10 seconds