public static class DesktopEventLoop Runs asynchronous application work while the process main thread services native events.
Remarks
DesktopEventLoop.Run picks the loop for the platform and the configured window host: the GTK 4 runner when the host uses it, the macOS AppKit loop on macOS, and a plain wait elsewhere.
Methods
Run
public static int Run(DesktopHostOptions options, Func<DesktopHost, Task<int>> application) Starts a Desktop host and runs application on the event loop its window host needs.
Parameters
optionsThe host options, for example
new DesktopHostOptions().WithGtk4().applicationThe application work. Its result becomes the return value.
Returns
The value returned by application.
Exceptions
InvalidOperationExceptionA Desktop event loop is already running in this process.
Remarks
Call this directly from Main, before any await, and return its result as the exit code. The options are validated and the host is built before a loop starts, so an options error never uses up a native toolkit's single per-process lifetime. The loop is picked from the platform and DesktopHostOptions.WindowHostFactory:
- A supported
IDesktopEventLoopWindowHostFactory, such as the GTK 4 factory set byWithGtk4(), runs its own main-thread loop. - On macOS, the AppKit loop of
DesktopEventLoop.Run. - Elsewhere, including Windows and Linux GTK 3, the call waits for the work.
An event-loop factory that is not supported, or whose IDesktopEventLoopWindowHostFactory.PrepareEventLoop reports that it cannot run (for example because no display is available), is not started. The reasons are reported as warnings to DesktopHostOptions.DiagnosticSink and the Desktop logger, and the host runs on the plain loop so a browser fallback can open. The host is disposed before the loop ends.
Run
public static void Run(Func<Task> application) Call from the synchronous process entry point. The loop stays alive through application shutdown and asynchronous native release. Other platforms simply join the task.
Exceptions
InvalidOperationExceptionA Desktop event loop is already running in this process.