The example opens two windows, Notebook and Preview. Call host.OpenWindow to put Preview in its own window. On desktop, OneApp runs on Linux (Wayland and X11), macOS (Apple silicon), and Windows.
Start from the zip, or run dotnet new console first.
dotnet add package RecursiveAI.OneAppRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneApp; using var host = AppHost.Create( new AppOptions("<h1>Notebook</h1>") { Title = "Notebook", Width = 420, Height = 260 }); var preview = host.OpenWindow( new AppWindowOptions("<h1>Preview</h1>") { Title = "Preview", Width = 320, Height = 200 }); var count = host.Windows.Count; Console.WriteLine($"Windows: {count}"); host.Run();
Close either window; the other stays open. The example exits when both are closed. Call OpenWindow on the UI thread; if a background operation needs to open a window, use host.Post to send the work to the UI thread instead.
Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.
Checked on Linux (X11): the app opens Notebook and Preview and prints:
Windows: 2Variations
For a dialog attached to the first window, replace the AppWindowOptions in the OpenWindow call. host is the AppHost created in Program.cs:
new AppWindowOptions("<h1>Preview</h1>") { Title = "Preview", Width = 320, Height = 200, Parent = host.MainWindow }
Checked on Linux (X11): closing Notebook ends the app even if the Preview dialog is open. The dialog isn’t a main window. Use an unparented window like the first example if you want Preview to keep the app open.
Related recipes
The short answer
Call host.OpenWindow(new AppWindowOptions(html)) on your existing AppHost. Omit Parent and Overlay to open an ordinary top-level window. Keep the returned AppWindow if you want to close it, change its title, or handle its Closed event later. Both windows use the same host.Run() loop.
How do I open two windows of one app?
Create the host once. AppHost.Create creates the first window, and each call to OpenWindow creates another. Pass the new window its own HTML; for controls in that window, attach handlers in that window’s Setup callback. A preview can render text from the same notebook without sharing the editor’s page or controls.
The example opens the preview at startup, but an Open Preview button can call the same API from its click handler. Decide what another click means before adding that button. For a single preview, hold on to its handle and check IsClosed before creating another. For document windows that should coexist, keep one handle per document instead.
Is a second window the same as a second app instance?
No. A second instance starts a separate process. A second window belongs to the existing app, so it can use the same in-memory data and event loop. Closing the first window also doesn’t tell an ordinary second window to close. The default policy, LastMainWindowClosed, ends the app when no main windows remain. If you want a tool window that doesn’t keep the app alive, set IsMain to false rather than assuming that “opened second” decides its lifetime.