Class wait
Contains functions to wait for a custom condition, handle, etc, or simply sleep.
public static class wait
Remarks
Specialized "wait for" functions are in other classes, for example wnd.wait.
All "wait for" functions have a timeout parameter. It is the maximal time to wait, in seconds. If 0, waits indefinitely. If > 0, throws System.TimeoutException when timed out. If < 0, then stops waiting and returns default value of that type (false
, etc).
While waiting, most functions by default don't dispatch Windows messages, events, hooks, timers, COM/RPC, etc. For example, if used in a Window/Form/Control event handler, the window would stop responding. Use another thread, for example async/await/Task, like in the example. Or Seconds.DoEvents.
Examples
wait.until(0, () => keys.isScrollLock);
print.it("ScrollLock now is toggled");
Using in a WPF window with async/await.
using System.Windows;
var b = new wpfBuilder("Window").WinSize(250);
b.R.AddButton("Wait", async _ => {
print.it("waiting for ScrollLock...");
var result = await Task.Run(() => wait.until(-10, () => keys.isScrollLock));
print.it(result);
});
if (!b.ShowDialog()) return;
Namespace: Au
Assembly: Au.dll
Methods
Name | Description |
---|---|
doEvents() | Retrieves and dispatches events and Windows messages from the message queue of this thread. |
doEvents(int) | Waits timeMS milliseconds. While waiting, retrieves and dispatches Windows messages and other events. |
doEventsUntil(Seconds, Func<bool>) | Waits for a condition to be changed while processing messages or other events received by this thread. |
forHandle(Seconds, WHFlags, params ReadOnlySpan<nint>) | Waits for a kernel object (event, mutex, etc). |
forPostedMessage(Seconds, WPMCallback) | Waits for a posted message received by this thread. |
ms(int) | Waits timeMilliseconds milliseconds. |
retry(Seconds, Action, Func<Exception, bool>) | Calls callback function action. If it throws an exception, waits/retries until it does not throw exceptions or until timeout. |
retry<T>(Seconds, Func<T>, Func<Exception, bool>) | Calls callback function func and returns its result. If it throws an exception, waits/retries until it does not throw exceptions or until timeout. |
s(double) | Waits timeSeconds seconds. The same as wait.ms, but the time is specified in seconds, not milliseconds. |
s(int) | Waits timeSeconds seconds. The same as wait.ms, but the time is specified in seconds, not milliseconds. |
until<T>(Seconds, Func<T>) | Waits for a user-defined condition. Until the callback function returns a value other than |