Asp.NET Core 2.1 HostedService

编程入门 行业动态 更新时间:2024-10-18 10:35:58
本文介绍了Asp.NET Core 2.1 HostedService-继续在Azure上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我们有一个使用IHostedService的Web应用程序.此处

我们在此处详细介绍了采用的方法

目标是要有一个能够连续运行后台任务的应用程序.因此,我们可以安排在设定的时间自动运行的作业.该应用程序与我们所有其他应用程序是分开的,因此我们的用户群不会访问它.因此,我们需要一种使该应用程序始终在Azure上运行的方法.

我们试图在Azure上为该应用程序设置一个应用程序服务,但是该应用程序似乎无法持续运行.一切似乎都可以在本地运行,但是在Azure上,我必须停止并重新启动该服务,然后才能启动IHostedService任务.

Azure上是否有一种方法可以使应用程序保持活动和运行状态?

解决方案

好,因此在Azure的应用程序设置"中,有一个 Always On 设置对我们有用.:)

我们还从Azure支持中发现,如果您位于其提供的软件包中的最低层,则将其视为开发"环境,并且正常运行时间将有限.结果,我们可以预期应用程序在达到该限制时将脱机.

我们认为仪表板中应该有一些更明显的东西,我们才能知道这一点.

一旦我们升级到标准层,该应用程序将保持在线状态.

此外,如果您正在运行托管服务,但遇到未处理的异常,则将停止该服务.您需要确保要处理异常才能使其正常工作.

We have a web application that is using the IHostedService. There is an example of this here

And the method we employed is detailed here

The goal was to have an application that continually ran background tasks. So we could schedule in jobs that run automatically at set times. This application is separate from all our other applications, so it's not visited by our user base. So we needed a way for this application to run all the time on Azure.

We tried to set up an App Service for the application on Azure, but it seems that the application does not continually run. Things seem to run locally ok, but on Azure, I have to stop and restart the service before it kicks in the IHostedService tasks.

Is there a way on Azure to keep the application alive and running?

解决方案

Ok, so in the App Settings in Azure, there is a setting Always On this worked for us. :)

We also found out from Azure support, that if you are on the lowest tier in their offered packages, this is treated as a "Development" environment and will only have limited up-time. As a result, we could expect the application to go offline when we reached that limit.

We argued that there should have been something more obvious in the dashboard for us to know this.

Once we upgraded to a Standard tier, the application stayed online.

Also, if you are running a hosted service and it hits an unhandled exception, this stops the service. You need to make sure you are handling exceptions for this to work.

更多推荐

Asp.NET Core 2.1 HostedService

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

发布评论

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

>www.elefans.com

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