Open Source Web Application Framework for ASP.NET Core
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

41 lines
1.1 KiB

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Threading;
namespace Volo.Abp.BackgroundJobs;
public class MyAsyncJob : AsyncBackgroundJob<MyAsyncJobArgs>, ISingletonDependency
{
public List<string> ExecutedValues { get; } = new List<string>();
public Guid? TenantId { get; set; }
private readonly ICurrentTenant _currentTenant;
private readonly ICancellationTokenProvider _cancellationTokenProvider;
public bool Canceled { get; set; }
public MyAsyncJob(
ICurrentTenant currentTenant,
ICancellationTokenProvider cancellationTokenProvider)
{
_currentTenant = currentTenant;
_cancellationTokenProvider = cancellationTokenProvider;
}
public override Task ExecuteAsync(MyAsyncJobArgs args)
{
if (_cancellationTokenProvider.Token.IsCancellationRequested)
{
Canceled = true;
}
ExecutedValues.Add(args.Value);
TenantId = _currentTenant.Id;
return Task.CompletedTask;
}
}