Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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); ?

like image 510
Ivan Kochurkin Avatar asked Nov 10 '12 21:11

Ivan Kochurkin


1 Answers

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);
like image 188
aschoenebeck Avatar answered Sep 21 '22 02:09

aschoenebeck