简体   繁体   中英

Equivalent of setTimeout and setInterval function in Script#

How to use setTimeout() and setInterval method in C# with Script#?

For example, how to write: setInterval(function(){alert("Hello")},3000); ?

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:

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() :

Script.ClearInterval(intervalid);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM