• This blog shows clear steps of how to add background job in orchard cms site.

    Presumption: Developer has basic knowledge of orchard core cms.

    Get basics of OrchardCore CMS here.

    You can find installation steps here.

    Get latest OrchardCore CMS from https://github.com/OrchardCMS/OrchardCore.

    Adding Job Scheduler in Orchard CMS can be achieved by implementing IBackgroundTask interface. The IBackgroundTask interface is one of the most simple interfaces you can find in Orchard. The only method contained in this interface you need to implement in your class is the DoWorkAsync method. Orchard will execute the DoWorkAsync method of every IBackgroundTask implementation every 1 minute, so it enables you to simply define some logic that will run periodically. It is useful for recurring tasks.

    Create a scheduler class say MyBackgroundJob.cs

    Inherit IBackgroundTask interface

    Implement DoWorkAsync method.

    public Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToken cancellationToken)
        {
            //logic here
        }
    

    Changes In startup.cs

    Add reference of OrchardCore.BackgroundTasks;

    Add below code in ConfigureServices method.

    services.AddSingleton<IBackgroundTask, MyBackgroundJob>();

    Note: Adding background task in service configuration won’t start scheduler. We need to enable it from admin panel.

    Steps to enable background tasks.

    Run the site.

    Login as an admin.

    Go to Modules > Enable Background Tasks.

    This will add menu item for Background Tasks

    Navigate to Background Tasks. You will find your scheduler listed here.

    By default, this scheduler will run at every 1 minute. You can change it editing task settings.

    You can create cron expression online here.

0 Years in
Operation
0 Loyal
Clients
0 Successful
Projects

Words from our clients

 

Tell Us About Your Project

We’ve done lot’s of work, Let’s Check some from here