Show / Hide Table of Contents

Struct WaitLoop

Can be used to easily implement "wait for" functions with a timeout.

public struct WaitLoop
Remarks

See examples. The code works like most "wait for" functions of this library: throws exception when timed out, unless the timeout value is negative. Similar code is used by wait.until<T> and many other "wait for" functions of this library.

Examples
public static bool WaitForMouseLeftButtonDown(Seconds timeout) {
	var x = new WaitLoop(timeout);
	for(; ; ) {
		if(mouse.isPressed(MButtons.Left)) return true;
		if(!x.Sleep()) return false;
	}
}

The same with wait.until.

static bool WaitForMouseLeftButtonDown2(Seconds timeout) {
	return wait.until(timeout, () => mouse.isPressed(MButtons.Left));
}

Namespace: Au.More
Assembly: Au.dll

Constructors

Name Description
WaitLoop(Seconds)

Sets timeout and possibly more wait parameters.

Properties

Name Description
Cancel

Can be used to cancel the wait operation.

MaxPeriod

Maximal period (WaitLoop.Sleep sleep time). Milliseconds. Initially it is Seconds.MaxPeriod, or WaitLoop.Period*50 if it is null (eg 10*50=500).

Period

Current period (WaitLoop.Sleep sleep time). Milliseconds. Initially it is Seconds.Period, or 10 ms if it was null. Then each WaitLoop.Sleep increments it until WaitLoop.MaxPeriod.

TimeRemaining

Gets or sets the remaining time. Milliseconds.

Methods

Name Description
IsTimeout()

If the timeout time is not expired, returns false. Else if the timeout was negative, returns true. Else throws System.TimeoutException.

Sleep()

Calls WaitLoop.IsTimeout. If it returns true, returns false. Else sleeps WaitLoop.Period milliseconds, increments Period if it is less than WaitLoop.MaxPeriod, and returns true.