如何使用 docker 在 dotnet 上正常关闭? [英] How to do gracefully shutdown on dotnet with docker?

查看:38
本文介绍了如何使用 docker 在 dotnet 上正常关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法优雅地关闭DOCKER中运行的DOTNET CORE应用程序?如果是,我应该听哪个事件?

Is there a way to gracefully shut-down a DOTNET CORE application which is running in DOCKER? If yes, which event I should listen?

我想要的只是在取消请求时我想将我的取消令牌传递给当前方法并在它们工作时推迟关闭.

All I want is upon cancellation request I would like to pass my cancellation token/s to current methods and postpone the shut-down while they are working.

寻找与 dotnet 核心相关而非通用信息的示例代码、参考链接等

Looking for a sample code, reference link etc. which are relevant to dotnet core and not generic info

更新这个问题不是 即使在 .net 核心控制台应用程序中使用 Console.ReadLine() docker 容器也会立即退出,因为我没有立即退出问题.我需要利用诸如 Windows.SystemsEvents.SessionEnding 之类的事件 而依赖 Console.CancelKeyPress 和/或实施 WebHostBuilder() 不符合要求.

UPDATE This question is not a duplicate of docker container exits immediately even with Console.ReadLine() in a .net core console application because I'm not having an immediate exit issue. I need to tap into event something like Windows.SystemsEvents.SessionEnding and relying on Console.CancelKeyPress and/or implementing WebHostBuilder() doesn't fit the bill.

推荐答案

在 .NET Core 2.0 中,您可以使用 AppDomain.CurrentDomain.ProcessExit 事件,该事件在 Docker 中的 Linux 上运行良好.AssemblyLoadContext.Default.Unloading 可能也能正常工作,甚至在 .NET Core 2.0 之前.

In .NET Core 2.0, you can use the AppDomain.CurrentDomain.ProcessExit event, which works fine on Linux in Docker. AssemblyLoadContext.Default.Unloading probably works as well, even before .NET Core 2.0.

这篇关于如何使用 docker 在 dotnet 上正常关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆