public void ScheduleBackgroundTask(Func <Task> task, ProgressBarReport progressBarReport) { lock (_gate) { _tasks = _tasks ?? new List <Task>(); _tasks.Add(Task.Run(() => CallBackgroundTask(task, progressBarReport))); } }
private async Task CallBackgroundTask(Func <Task> task, ProgressBarReport report) { CurrentReport = report; Interlocked.Increment(ref _backgroundTaskCount); try { await task(); } catch (Exception ex) { Debug.LogError(ex); } Interlocked.Decrement(ref _backgroundTaskCount); }
public void ScheduleForegroundTask(Action task, ProgressBarReport report) { ScheduleForegroundTask(() => ActionAsEnumerable(task, report)); }
private static IEnumerable <ProgressBarReport> ActionAsEnumerable(Action task, ProgressBarReport report) { yield return(report); task(); }