Periodic Task

Is there a suggested way to add a function which needs to be run periodically in the background?

We don't suggest a particular way to do that but some of our users are relying on Hangfire. Check this thread for example Access to database context from server code

This is the way that I integrate hangfire:

1 - Go to server folder and install nuget packages: hangfire.core, hangfire.aspnetcore, hangfire.sqlserver
2 - Add a file Startup.Custom.cs in server project and add namespaces and code:
using Hangfire;
using Hangfire.Server;
using Hangfire.Common;

public partial class Startup
{
partial void OnConfigureServices(IServiceCollection services)
{
services.AddHangfire(configuration =>{
configuration.UseSqlServerStorage(Configuration.GetConnectionString("YourConnectionString"));
});
}

partial void OnConfigure(IApplicationBuilder app)
{
    app.UseHangfireServer();

    // FireAndForget Task
    BackgroundJob.Enqueue(() => StaticClass.StaticMethod(Configuration.GetConnectionString("YourConnectionString")));  

    // Recurring Task
    RecurringJob.AddOrUpdate(() => StaticClass.StaticMethod(Configuration.GetConnectionString("YourConnectionString")), Cron.Daily);

}

Use of hangfire dashboard collide with angular router and for this reason we use custom pages to show queue data.

2 Likes

I'm just wondering whether there's a simpler way that doesn't depend on SQL Server.

@tlanier any solution that works with ASP.NET Core applications would work with Radzen. For example background tasks with hosted services.