Ivan Kochurkin
Ivan Kochurkin

Reputation: 4501

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

Upvotes: 12

Views: 15739

Answers (1)

aschoenebeck
aschoenebeck

Reputation: 449

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

Upvotes: 7

Related Questions