Question

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

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

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top