ASP.NET 核心托管服务中从哪里开始监控队列
Where to start monitoring queue in ASP.NET Core hosted service
我关注的 this example for a queued hosted service to add this to an ASP.NET Core application, and it's not clear to me where StartMonitorLoop
should be called. I ended up modifying it to be EnsureMonitorLoop
, added a check so that it's the call to Task.Run
is only made once, added a MonitorLoop
parameter to constructor for my API controller, and called EnsureMonitorLoop
from there. It smells kind of funny to me that the API controller constructor should be kicking off monitoring the queue. The example Program.cs
似乎与 Visual Studio 为我生成的非常不同。我的使用 WebHost.CreateDefaultBuilder(args).UseStartup<Startup>
方法。那就是他们称之为 StartMonitorLoop
.
的地方
调用 StartMonitorLoop
的正确位置在哪里,为什么?谢谢!
这里的文档不是很清楚,但 MonitorLoop
实际上不是其中的一部分。这是一个在控制台应用程序中使用的示例服务,只是为了演示排队的后台工作人员如何工作。您可以从这个 class 中为您的应用程序获取一些灵感,但是 StartMonitorLoop
的概念根本不适用于 ASP.NET Core。
更清楚一点:例如,在实际操作中,您会将 IBackgroundTaskQueue
注入控制器 class,然后向其添加一些任务,就像 MonitorLoop
确实(没有所有的键输入爵士乐)。你实际上不会有 MonitorLoop
或类似的东西。
我关注的 this example for a queued hosted service to add this to an ASP.NET Core application, and it's not clear to me where StartMonitorLoop
should be called. I ended up modifying it to be EnsureMonitorLoop
, added a check so that it's the call to Task.Run
is only made once, added a MonitorLoop
parameter to constructor for my API controller, and called EnsureMonitorLoop
from there. It smells kind of funny to me that the API controller constructor should be kicking off monitoring the queue. The example Program.cs
似乎与 Visual Studio 为我生成的非常不同。我的使用 WebHost.CreateDefaultBuilder(args).UseStartup<Startup>
方法。那就是他们称之为 StartMonitorLoop
.
调用 StartMonitorLoop
的正确位置在哪里,为什么?谢谢!
这里的文档不是很清楚,但 MonitorLoop
实际上不是其中的一部分。这是一个在控制台应用程序中使用的示例服务,只是为了演示排队的后台工作人员如何工作。您可以从这个 class 中为您的应用程序获取一些灵感,但是 StartMonitorLoop
的概念根本不适用于 ASP.NET Core。
更清楚一点:例如,在实际操作中,您会将 IBackgroundTaskQueue
注入控制器 class,然后向其添加一些任务,就像 MonitorLoop
确实(没有所有的键输入爵士乐)。你实际上不会有 MonitorLoop
或类似的东西。