Added comments

This commit is contained in:
Thorsten Sommer 2024-02-05 20:13:12 +01:00
parent e910ccfd97
commit 4707459ef9
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108

View File

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