public static RestartingBackgroundTask Start( Func <CancellationToken, Task> taskToRun, ILogger logger, RestartingBackgroundTaskOptions restartingBackgroundTaskOptions) { return(new(taskToRun, logger, restartingBackgroundTaskOptions)); }
private RestartingBackgroundTask( Func <CancellationToken, Task> taskToRun, ILogger logger, RestartingBackgroundTaskOptions restartingBackgroundTaskOptions) { _taskToRun = taskToRun; _logger = logger; _name = restartingBackgroundTaskOptions.Name; _onException = restartingBackgroundTaskOptions.OnException; _id = Guid.NewGuid(); _internalCancellationTokenSource = restartingBackgroundTaskOptions.CancellationToken.HasValue ? CancellationTokenSource.CreateLinkedTokenSource(restartingBackgroundTaskOptions.CancellationToken.Value) : new CancellationTokenSource(); Task.Factory.StartNew(ExecuteTask, TaskCreationOptions.LongRunning); }