如何使用docker在dotnet上正常关闭?

编程入门 行业动态 更新时间:2024-10-28 12:22:34
本文介绍了如何使用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

更新 这个问题不是即使在核心控制台应用程序中使用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 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上正常关闭?

本文发布于:2023-10-24 05:56:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523109.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   docker   dotnet

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!