javascript 等效于脚本中的 setTimeout 和 setInterval 函数#
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13326230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Equivalent of setTimeout and setInterval function in Script#
提问by Ivan Kochurkin
How to use setTimeout()
and setInterval
method in C# with Script#?
如何使用Script#在C#中使用setTimeout()
和setInterval
方法?
For example, how to write: setInterval(function(){alert("Hello")},3000);
?
例如,如何写:setInterval(function(){alert("Hello")},3000);
?
采纳答案by aschoenebeck
SetTimeout()
and SetInterval()
are part of the Script
class (or Window
for previous versions of Script# < 0.8). You use them like this with an inline delegate:
SetTimeout()
并且SetInterval()
是Script
类的一部分(或Window
对于以前版本的 Script# < 0.8)。您可以像这样使用内联委托来使用它们:
int intervalid = Script.SetInterval(delegate { Window.Alert("Hello"); }, 3000);
Or you can write an explicit handler function:
或者您可以编写一个显式处理程序函数:
Script.SetTimeout(TimeoutHandler, 3000);
void TimeoutHandler() {
Window.Alert("Hello");
}
To discard the timer interval later you can use ClearInterval()
:
要稍后丢弃计时器间隔,您可以使用ClearInterval()
:
Script.ClearInterval(intervalid);