Created
September 23, 2024 14:46
-
-
Save lostmsu/e4e187200553c459ea24e8b03f3e1754 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "nuget: Microsoft.AspNetCore.App, 2.2.8" | |
using System.Net.Http; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
var log = app.Services.GetRequiredService<ILogger<WebApplication>>(); | |
app.MapGet("/", | |
async (CancellationToken cancel) => | |
{ | |
try | |
{ | |
await Task.Delay(TimeSpan.FromSeconds(60), cancel); | |
log.LogCritical("NOT CANCELLED!"); | |
} | |
catch (OperationCanceledException) | |
{ | |
log.LogError("Cancelled"); | |
} | |
}); | |
const string uri = "http://localhost:17825"; | |
var http = new HttpClient(); | |
new Thread(() => | |
{ | |
try | |
{ | |
using var cancel = new CancellationTokenSource(TimeSpan.FromSeconds(1)); | |
using var _ = http.GetAsync(uri, cancel.Token).Result; | |
} | |
catch { } | |
}) | |
{ | |
IsBackground = true, | |
}.Start(); | |
app.Run(uri); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment