Net8Blazor/NET8Blazor/PhotinoNetApp/Program.cs

53 lines
1.3 KiB
C#
Raw Permalink Normal View History

using System.Drawing;
using PhotinoNET;
2024-01-24 18:22:13 +00:00
using PhotinoNetApp.Components;
2024-02-05 19:13:12 +00:00
//
// Standard .NET 8 template for web apps:
//
2024-01-24 18:22:13 +00:00
var builder = WebApplication.CreateBuilder();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
2024-02-05 18:38:36 +00:00
builder.WebHost.UseWebRoot("wwwroot");
2024-01-24 18:22:13 +00:00
builder.WebHost.UseStaticWebAssets();
2024-02-05 19:13:12 +00:00
// I specified the URL with a port:
builder.WebHost.UseUrls("http://localhost:5000");
var app = builder.Build();
2024-02-05 18:38:36 +00:00
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
2024-02-05 19:13:12 +00:00
//
// End of standard template
//
// Using a cancellation token source, so we can exit the web server later:
2024-01-24 18:22:13 +00:00
using var webServerCancellation = new CancellationTokenSource();
2024-02-05 19:13:12 +00:00
// Run the webserver async in the background (no await used here):
var webServerTask = app.RunAsync(webServerCancellation.Token);
2024-02-05 19:13:12 +00:00
// Create the Photino window:
var window = new PhotinoWindow()
.SetTitle("Test App")
.SetUseOsDefaultSize(false)
.SetSize(new Size(1024, 900))
.Center()
.SetResizable(true)
2024-02-05 19:13:12 +00:00
// ... and load the web content at the URL / port:
.Load("http://localhost:5000");
2024-02-05 19:13:12 +00:00
// Wait until the Photino window was closed:
window.WaitForClose();
2024-02-05 19:13:12 +00:00
// Cancel the webserver using the token:
webServerCancellation.Cancel();
2024-02-05 19:13:12 +00:00
// Wait for the server to stop:
await webServerTask;