private static async Task RunTask(BackgroundTask backgroundTask, int minExecutionCount = 1) { backgroundTask.ActivateTask(); var task = backgroundTask.StartAsync(cancellationToken: CancellationToken.None) .ConfigureAwait(continueOnCapturedContext: false); var watch = Stopwatch.StartNew(); while (minExecutionCount > backgroundTask.GetExecutionCount() && watch.ElapsedMilliseconds < 60000) { await Task.Delay(millisecondsDelay : 100).ConfigureAwait(continueOnCapturedContext: false); } backgroundTask.DeactivateTask(); await task; }