Show / Hide Table of Contents

Method wait.doEventsUntil


Overload

Waits for a condition to be changed while processing messages or other events received by this thread.

public static bool doEventsUntil(Seconds timeout, Func<bool> condition)
Parameters
timeout  (Seconds)

Timeout, seconds. Can be 0 (infinite), >0 (exception) or <0 (no exception). More info: Wait timeout.

condition  (Func<bool>)

Callback function that returns true to stop waiting. More info in Remarks.

Returns
bool

Returns true. On timeout returns false if timeout is negative; else exception.

Exceptions
TimeoutException

timeout time has expired (if > 0).

Remarks

While waiting, dispatches Windows messages etc, like wait.doEvents. After dispatching one or more messages or other events (posted messages, messages sent by other threads, hooks, COM, APC, etc), calls the callback function. Stops waiting when it returns true. Similar to wait.until<T>. Differences: 1. Always dispatches messages etc. 2. Does not call the callback function when there are no messages etc. 3. Does not use WaitLoop and Seconds.Period/MaxPeriod/DoEvents.

Examples

bool stop = false;
timer.after(2000, t => { print.it("timer"); stop = true; });
wait.doEventsUntil(5, () => stop);
print.it(stop);