is it possible to wait a running task when gracefully shutdown? #27243
Unanswered
rider11-dev
asked this question in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
1. Hi,i'm using IHostApplicationLifetime(aspnetcore3.1) to shutdown my webapp,like below:
endpoints.Map("/stop", async (httpContext) => { var logger = httpContext.RequestServices.GetRequiredService<ILoggerFactory>().CreateLogger("ApplicationStop"); var sw = new Stopwatch(); sw.Start(); var applicationLifetime = httpContext.RequestServices.GetRequiredService<IHostApplicationLifetime>(); applicationLifetime.StopApplication(); sw.Stop(); await httpContext.Response.WriteAsync($"app stopped in {sw.Elapsed.TotalSeconds} secs"); });
2. It worked and requests in process have chance to finish in certain time(configured by HostOptions.ShutdownTimeout).
3. That is to say,when applicationLifetime.StopApplication called,the app wait a certain time for requests to process.
4. So,i wonder if it is possible the app wait some time for a runing task before shutdown?some task like below:
`
endpoints.Map("/task_sleep", async ctx =>
{
var logger = ctx.RequestServices.GetRequiredService().CreateLogger("task_sleep");
int.TryParse(ctx.Request.Query["sec"], out int sec);
`
thanks!
Beta Was this translation helpful? Give feedback.
All reactions