[英]Fire Cron job automatically when application run .Net core 6
I have created a cron job in an API controller in .NET Core 6 as follows:我在 .NET Core 6 中的 API controller 中创建了一个 cron 作业,如下所示:
[HttpGet]
[Route("api/RunMyJob")]
public void RunMyJob()
{
RecurringJob.AddOrUpdate(() => jobmethod(), Cron.DayInterval(5));
}
[NonAction]
public async Task jobmethod()
{
// ........
}
I want to fire this job automatically when the project is run, without calling the API in the browser.我想在项目运行时自动触发此作业,而不是在浏览器中调用 API。
Please check the official doc about Background tasks with hosted services in ASP.NET Core .请查看有关ASP.NET Core 中托管服务的后台任务的官方文档。
Best code examples:最佳代码示例:
In ASP.NET Core 3.1, how can I schedule a background task (Cron Jobs) with hosted services for a specific date and time in the future? 在 ASP.NET Core 3.1 中,如何在未来的特定日期和时间安排具有托管服务的后台任务(Cron 作业)?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.