Open Closed

Add recurring job at run time #4076


User avatar
0
andmattia created
  • ABP Framework version: v5.3.1
  • UI type: Angular
  • DB provider: EF Core

HI how can I add a recurring job at run time? and how can I remove it?

so I try to add via startup but I try to read polling intervall via appsettings.json but I can't do it

 public PollingWorker()
    {
        //_options = ServiceProvider.GetService<IOptions<Dataptions>>().Value; --> Null exception
        RecurringJobId = nameof(PollingWorker);
        CronExpression = Cron.MinuteInterval(2);
    }

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

5 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Did you use hangfire or Quartz?

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    andmattia created

    Hangfire

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    how can I add a recurring job at run time? and how can I remove it?

    You can refer to the Hangfire API. https://docs.hangfire.io/en/latest/index.html

    so I try to add via startup but I try to read polling intervall via appsettings.json but I can't do it

    You can try to inject IConfiguration to reading the appsettings

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    andmattia created

    How can I inject Iconfiguration?

     public override async Task OnApplicationInitializationAsync(
            ApplicationInitializationContext context)
        {
            await context.AddBackgroundWorkerAsync<PollingWorker>();
        }
    

    If I add an IServiceProvider I get this error

    annot resolve parameter 'Microsoft.Extensions.DependencyInjection.IServiceCollection service' of constructor 'Void .ctor(Microsoft.Extensions.DependencyInjection.IServiceCollection)'.
       at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable`1 parameters)
       at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
       at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action`1 next)
       at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.&lt;&gt;c__DisplayClass14_0.&lt;BuildPipeline&gt;b__1(ResolveRequestContext ctxt)
    
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    What is your PollingWorker class? You can inject services on the constructor or method context.

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 16, 2026, 14:50
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.