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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With