Window.setIdleCommand

Set a callback to be executed after a delay and after processing all other events. The callback is executed only once and discarded. This is useful for refreshing the GUI at regular intervals when monitoring something or to schedule a future action.

class Window
setIdleCommand
(
this T
)

Parameters

callback CommandCallback

The delegate function to be executed on idle.

msDelay int

The delay in millisecond before executing the given callback.

Return Value

Type: auto

This window to aid method chaining.

Examples

InputStream stream = ...; // A data provider.

this.mainWindow.setIdleCommand(delegate(CommandArgs args){

	// Use data.
	if (!stream.empty && stream.finished)
	{
		performStep(stream.next);
	}

	// Re-arm this callback and wait for more data.
	this.mainWindow.setIdleCommand(args.callback, 10_000);

}, 10_000);

Caveats: The callback executed by this method is not asynchronous and could halt the GUI from processing events if it takes a long time to finish.

Meta