Goodmorning,
this is the first time I write in this forum.
My name is Ciro.
I’m using Hangfire for a production web application project.
My question is about safety of checking cancellationToken status in another thread respect of the main thread of the job .
The code I want to execute is the following:
public void exec(List<object> parameters = null, bool useCancellationToken = false, IJobCancellationToken cancellationToken = null) {
//cancellation job logic
if (useCancellationToken && cancellationToken != null && cancellationToken != JobCancellationToken.Null) {
Task.Run(() => {
for (var i = 0; i < Int32.MaxValue; i++) {
cancellationToken.ThrowIfCancellationRequested();
Thread.Sleep(TimeSpan.FromSeconds(1));
}
});
}
//job execution
job_implementation(parameters);
}
Thank you all
Best regards
Ciro Corvino