52 lines
1.1 KiB
Plaintext
52 lines
1.1 KiB
Plaintext
<div style="padding:1rem; border:1px solid #ccc; border-radius:8px; max-width:350px;">
|
|
<h4>Execution Context Test</h4>
|
|
|
|
<p>
|
|
<strong>Context:</strong>
|
|
<span style="color:@(IsWasm ? "green" : "blue")">
|
|
@(IsWasm ? "WebAssembly (Client)" : "Server")
|
|
</span>
|
|
</p>
|
|
|
|
<p>
|
|
<strong>Time:</strong> @CurrentTime.ToLongTimeString()
|
|
</p>
|
|
|
|
<button class="btn btn-primary btn-sm" @onclick="DoClick">Test Me</button>
|
|
<p>
|
|
@lblOut
|
|
</p>
|
|
</div>
|
|
|
|
@code {
|
|
bool IsWasm = false;
|
|
DateTime CurrentTime = DateTime.Now;
|
|
System.Timers.Timer? timer;
|
|
|
|
private string lblOut = "";
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
// Funziona sia in Server che in WASM
|
|
IsWasm = OperatingSystem.IsBrowser();
|
|
|
|
timer = new System.Timers.Timer(1000);
|
|
timer.Elapsed += (_, _) =>
|
|
{
|
|
CurrentTime = DateTime.Now;
|
|
InvokeAsync(StateHasChanged);
|
|
};
|
|
timer.Start();
|
|
}
|
|
|
|
private void DoClick()
|
|
{
|
|
lblOut = $"Clicked | {DateTime.Now:HH:mm:ss}";
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
timer?.Dispose();
|
|
}
|
|
}
|