DesktopEventLoop class

Namespace Runic.Desktop · Runic.Desktop 0.7.0-preview.5

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

options

The host options, for example new DesktopHostOptions().WithGtk4().

application

The application work. Its result becomes the return value.

Returns

The value returned by application.

Exceptions

InvalidOperationException

A 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:

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

InvalidOperationException

A Desktop event loop is already running in this process.