public BackgroundTaskHost( IServiceProvider backgroundServices, IBackgroundTaskStore store, IBackgroundTaskSerializer serializer, ITypeResolver typeResolver, IOptionsMonitor <BackgroundTaskOptions> options, ISafeLogger <BackgroundTaskHost> logger) { _backgroundServices = backgroundServices; Store = store; Serializer = serializer; _typeResolver = typeResolver; _options = options; _logger = logger; options.OnChange(OnSettingsChanged); _schedulers = new ConcurrentDictionary <int, TaskScheduler>(); _factories = new ConcurrentDictionary <TaskScheduler, TaskFactory>(); _pending = new ConcurrentDictionary <object, HandlerHooks>(); _cancel = new CancellationTokenSource(); // dispatch thread _background = new PushQueue <IEnumerable <BackgroundTask> >(); _background.Attach(WithPendingTasks); _background.AttachBacklog(WithOverflowTasks); _background.AttachUndeliverable(WithFailedTasks); // maintenance thread _maintenance = new PushQueue <IEnumerable <BackgroundTask> >(); _maintenance.Attach(WithHangingTasks); _maintenance.AttachBacklog(WithHangingTasks); _maintenance.AttachUndeliverable(WithFailedTasks); }
private static BackgroundTask NewTask(BackgroundTaskOptions options, IBackgroundTaskSerializer serializer, Type type, object userData) { var handlerInfo = new HandlerInfo(type.Namespace, type.Name); var task = new BackgroundTask { Handler = serializer?.Serialize(handlerInfo), Data = userData == null ? null : JsonSerializer.Serialize(userData) }; options.ProvisionTask(task); return(task); }