how to stop an “ex” like that. The canceltaion token is not always supported in Execute method. I would always like to kill task.
try
{
var ex = Execute(parameters, cancellationToken, performContext);
await Task.WhenAny(ex
,
ThrowIfCancellationRequested(ex, cancellationToken));
return;
}
catch (Exception ex)
{
_loggerService.LogError(ex, "JobBase execute internal with raw params without job semaphore.");
throw;
}
private async Task ThrowIfCancellationRequested(Task task, CancellationToken cancellationToken)
{
try
{
while (true)
{
await Task.Delay(5000, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
}
}
catch
{
task.Dispose();
}
}
protected override async Task Execute(Parameter parameter,
CancellationToken cancellationToken,
PerformContext performContext = null)
{
while (true)
{
await Task.Delay(TimeSpan.FromSeconds(10));
}
}
próbwałem chyba wszystkiego i nie mam pojęcią jak ubić zadanie.
methoda execute cały czas działa pomimo tego ze robie dispose na catch
New contributor