gpt4 book ai didi

c# - ASP.NET Core 世界中的即发即弃的 native /规范方法

转载 作者:太空狗 更新时间:2023-10-29 19:46:26 25 4
gpt4 key购买 nike

做一些与 websockets 相关的编码,我发现目前还不清楚,如何正确处理长时间运行的后台进程或通过即发即弃语义执行的任务(这对于 ASP.NET 仍然正确Core 2.0),因为 DI 范围、应用重启等可能存在一些缺陷。

因此,获得一些明智的想法如何在 .NET Core 世界中实现此类事情而不需要像 Hangfire 这样的奇特东西将是一件很好的事情

最佳答案

可能值得查看有关 IHostedServiceBackgroundService 类的 MSDN 开发人员博客:

总结:

The IHostedService interface provides a convenient way to start background tasks in an ASP.NET Core web application (in .NET Core 2.0) or in any process/host (starting in .NET Core 2.1 with IHost). Its main benefit is the opportunity you get with the graceful cancellation to clean-up code of your background tasks when the host itself is shutting down.

关于c# - ASP.NET Core 世界中的即发即弃的 native /规范方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45944662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com