Replies: 4 comments 2 replies
-
Hi! Check out this issue for details on what you can try: #216 This is not an official feature at the moment, but you can take this approach. |
Beta Was this translation helpful? Give feedback.
-
Related to #141 |
Beta Was this translation helpful? Give feedback.
-
@jamesmh I thought about another option to stop long running task. I can schedule it to run once and to setup the invocable with cancellation token. Once i set the cancellation token , the invokable will exit and the task should be stopped. |
Beta Was this translation helpful? Give feedback.
-
I checked all the other comments and issues and came up with minimal demonstration of "how to cancel scheduled task": //Program.cs
builder.Services.AddScheduler();
var app = builder.Build();
IScheduler scheduler = app.Services.GetService<IScheduler>()!;
int ii = 0;
scheduler.Schedule(()=> {
Console.WriteLine("Hit the scheduler ");
if (ii++ >= 3)
{
bool isSuccess = (scheduler as Scheduler)!.TryUnschedule("SomeId");
Console.WriteLine($"Is Success: {isSuccess}");
}
}).EverySecond().PreventOverlapping("SomeId"); Results in: Hit the scheduler
Hit the scheduler
Hit the scheduler
Hit the scheduler
Is Success: True |
Beta Was this translation helpful? Give feedback.
-
Hi, i want to integrate Coravel nuget in my projet and i want to understand how i stop scheduler.
This is how i schedule new task :
provider.UseScheduler(scheduler =>
{
scheduler.Schedule(
() => Console.WriteLine("Every minute during the week.")
)
.EveryMinute()
.Weekday();
});
But how i can stop it?
I read the documentation from here but i did not find any reference how i stop it.
Another question that i have what is the best way to schedule tasks when i don't know from the application startup what i need to schedule.
My scenario is as follows first of all the application needs to query some service for the information and after that it will know to schedule tasks based on this information.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions