# Execute PriceAgentScheduler from code (not with the "refresh=true" URL)

**URL:** <https://forum.litium.com/t/execute-priceagentscheduler-from-code-not-with-the-refresh-true-url/1196>\
**Category:** Questions\
**Tags:** litium-6\
**Created:** [November 11, 2019, 9:27am UTC](https://forum.litium.com/t/execute-priceagentscheduler-from-code-not-with-the-refresh-true-url/1196 "2019-11-11T09:27:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cissi](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/cissi/32/18_2.png) [@Cissi](https://forum.litium.com/u/Cissi)\
**Post date:** [November 11, 2019, 9:27am UTC](https://forum.litium.com/t/execute-priceagentscheduler-from-code-not-with-the-refresh-true-url/1196/1 "2019-11-11T09:27:07Z")

</div>

I want a way to trigger a scheduled task by code. Instead of using the refresh=true url. That url creates a webrequest and it gets a timeout.  
So I want to make it possible with our own url to get the scheduled task and say: start in 2 minutes.

Litium version: 6.3.7

---

<div class="post-metadata">

**Author:** ![NilsN](https://yyz2.discourse-cdn.com/flex030/user_avatar/forum.litium.com/nilsn/32/302_2.png) [@NilsN](https://forum.litium.com/u/NilsN)\
**Post date:** [November 11, 2019, 1:14pm UTC](https://forum.litium.com/t/execute-priceagentscheduler-from-code-not-with-the-refresh-true-url/1196/2 "2019-11-11T13:14:12Z")

</div>

Maybe you could try something like this (I just stuck in a test controller):

```auto
using Litium.Application.Runtime;
using Litium.Foundation.Security;
using Litium.Scheduler;
using Litium.Web.Products.PriceAgents;
using Microsoft.Extensions.Logging;
using System;
using System.Threading.Tasks;
using System.Web.Mvc;

namespace Litium.Accelerator.Mvc.Controllers
{
    public class TestController : LitiumController
    {
        private readonly SchedulerService _schedulerService;

        public TestController(SchedulerService schedulerService)
        {
            _schedulerService = schedulerService;
        }

        public ActionResult Index()
        {
            _schedulerService.ScheduleJob<ExecutePriceAgentTask>(x => x.Run(), new ScheduleJobArgs { ExecuteAt = DateTime.Now.AddMinutes(2) });

            return new EmptyResult();
        }
    }

    public class ExecutePriceAgentTask
    {
        private readonly ILogger<IPriceAgentItemFactory> _logger;
        private readonly RollingFileService _rollingFileService;

        public ExecutePriceAgentTask(
            ILogger<IPriceAgentItemFactory> logger,
            RollingFileService rollingFileService)
        {
            _logger = logger;
            _rollingFileService = rollingFileService;
        }

        public Task Run()
        {
            var priceAgentScheduler = new PriceAgentScheduler(_logger, _rollingFileService);
            priceAgentScheduler.ExecuteTask(SecurityToken.CurrentSecurityToken, null);

            return Task.CompletedTask;
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex030/uploads/litium/original/1X/12eddac3b8b661de1db86af10ac8151b571e6fb9.png) [@system](https://forum.litium.com/u/system)\
**Post date:** [December 9, 2019, 1:14pm UTC](https://forum.litium.com/t/execute-priceagentscheduler-from-code-not-with-the-refresh-true-url/1196/3 "2019-12-09T13:14:20Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
