IScheduledTask - Task not created again

151 Views Asked by At

I have a Service method which is run by task scheduler. The task is created and is executed, but the task does not gets created again. Please see the following code:

Feature Handler : Task is created here

public class NewsFeatureEventHandler : IFeatureEventHandler
{
    private const int TimeIntervalMinutes = 1;
    private const string TaskType = "Feeds";

    ...

    public void Enabled(Feature feature)
    {
        if (feature.Descriptor.Id.Equals("My.Module"))
            _taskManager.CreateTask(TaskType, DateTime.UtcNow.AddMinutes(TimeIntervalMinutes), null);
    }
    ...        
}

ScheduledTaskHandler : Task is re-created here

public class MyScheduledTaskHandler : IScheduledTaskHandler
{
private const int TimeIntervalMinutes = 1;
    private const string TaskType = "Feeds";

public void Process(ScheduledTaskContext context)
    {
    try
    {
        ...
    }
    catch
    {
    ...
    }
    finally
    {
        _taskManager.CreateTask(TaskType, DateTime.UtcNow.AddMinutes(TimeIntervalMinutes), null);
    }
}
}

Can you see any problem with the above code. Please give some suggestions and direction.

Regards,

0

There are 0 best solutions below