---
title: "Waking the event loop from another thread"
url: https://recursiveai.org/oneplatform/docs/waking-the-loop/
description: "PlatformApp.PumpEvents(timeout) blocks until the system has an event or the timeout passes. Work that arrives on another thread (a request from a control…"
version: "1.0.0"
source: https://github.com/recursive-ai-oss/oneplatform-csharp/blob/37f5a73c449624ea8671f8612d61000e2d57aa5e/docs/waking-the-loop.md
---

# Waking the event loop from another thread

`PlatformApp.PumpEvents(timeout)` blocks until the system has an event or the timeout passes. Work that arrives on another thread (a request
from a control listener, a D-Bus callback, a timer, a task continuation) calls `PlatformApp.Wake()` to end that wait at once, so the loop
needs no polling interval.

- `Wake()` is safe from any thread, any number of times, at any time, including during `Dispose`.
- It makes the current wait return; if no wait is running, the next one returns immediately. Wakes that pile up before the loop looks
  coalesce into one early return.
- A woken `PumpEvents` queues no event. After every return, check your own work queue.
- A wake is not an event, so there is no `PlatformEventKind` for it.

| Backend | Mechanism |
|---|---|
| Wayland, X11 | A non-blocking pipe polled beside the connection descriptor. A flag keeps a burst of wakes to one byte. |
| Headless | A timed pump sleeps on a semaphore while nothing is queued; `Wake` releases it. |
| Win32 | An auto-reset event passed to `MsgWaitForMultipleObjects` beside the message queue. |
| Cocoa | An application-defined `NSEvent` posted with `postEvent:atStart:`, which may be called from any thread. |
| Android | `ALooper_wake` on the loop's looper. |
| Browser, iOS | No blocking wait; `Wake()` does nothing. |

Headless `PumpEvents(timeout)` used to return at once; it now waits up to `timeout` when no event is queued and no wake arrives.
