开发者

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

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.开发者_StackOverflow中文版 If there isn't a sleep function that is available to the script, then what's the next best thing?


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜