WScript.Sleep 和 window.timeout 的替代方案 [英] Alternative for WScript.Sleep and window.timeout
问题描述
我正在为在不支持 WScript
的工业控制器上运行的应用程序编写 VBScript.控制器有一个用于处理 VBScript 的线程,我只需要暂停我的脚本进行几次程序扫描,以允许另一个事件处理程序进行处理.VBScript 在 WSH shell 中处理.如果我运行 MsgBox
并弹出一条消息,它会释放脚本来执行它需要的操作,并且一切正常,但我无法弹出消息框.
I am writing a VBScript for an application that runs on an industrial controller which does not support WScript
. The controller has a single thread for processing VBScript and I need to pause my script for only a few program scans to allow another event handler to process. VBScript is processed in a WSH shell. If I run a MsgBox
and popup a message it frees the script to do what it needs to and everything works fine but I cannot have a message box popping up.
我读过的所有内容都建议使用 WScript.Sleep
,但我无法使用.
Everything I have read suggests using WScript.Sleep
but that is not available to me.
这不会在 Web 浏览器中运行,因此 window.timeout 对象不可用.我无法访问 WScript.Sleep 所以这不是一个选项.
This does not run in a web browser so the window.timeout object is not available. I cannot access WScript.Sleep so that is not an option.
推荐答案
如果秒的粒度对你来说足够细,并且你的操作系统是 Windows Vista 或更高版本,你可以以此脚本为例来说明如何等待三秒:
If the granularity of seconds is fine enough for you and your operating system is Windows Vista or higher, you can take this script as a sample of how to wait for three seconds:
MsgBox (Now()), , "1"
WScript.CreateObject("WSCript.shell").Run "timeout.exe /T 3", 0, True
MsgBox (Now()), , "2"
这篇关于WScript.Sleep 和 window.timeout 的替代方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!