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 |
Period | Current period (WaitLoop.Sleep sleep time). Milliseconds.
Initially it is Seconds.Period, or 10 ms if it was |
TimeRemaining | Gets or sets the remaining time. Milliseconds. |
Methods
Name | Description |
---|---|
IsTimeout() | If the timeout time is not expired, returns |
Sleep() | Calls WaitLoop.IsTimeout. If it returns |