added sync help buttons

This commit is contained in:
Luke Pulverenti 2015-01-28 22:58:39 -05:00
parent 83ec91f836
commit 82fe244fa1

View File

@ -563,18 +563,15 @@ namespace MediaBrowser.Controller.Entities
var children = ActualChildren.ToList(); var children = ActualChildren.ToList();
var percentages = new Dictionary<Guid, double>(children.Count); var percentages = new Dictionary<Guid, double>(children.Count);
var numComplete = 0;
var tasks = new List<Task>(); var count = children.Count;
foreach (var child in children) foreach (var child in children)
{ {
if (tasks.Count >= 2)
{
await Task.WhenAll(tasks).ConfigureAwait(false);
tasks.Clear();
}
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
if (child.IsFolder)
{
var innerProgress = new ActionableProgress<double>(); var innerProgress = new ActionableProgress<double>();
// Avoid implicitly captured closure // Avoid implicitly captured closure
@ -585,28 +582,30 @@ namespace MediaBrowser.Controller.Entities
{ {
percentages[currentChild.Id] = p / 100; percentages[currentChild.Id] = p / 100;
var percent = percentages.Values.Sum(); var innerPercent = percentages.Values.Sum();
percent /= children.Count; innerPercent /= count;
percent *= 100; innerPercent *= 100;
progress.Report(percent); progress.Report(innerPercent);
} }
}); });
if (child.IsFolder)
{
await RefreshChildMetadata(child, refreshOptions, recursive, innerProgress, cancellationToken) await RefreshChildMetadata(child, refreshOptions, recursive, innerProgress, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
else else
{ {
// Avoid implicitly captured closure await RefreshChildMetadata(child, refreshOptions, false, new Progress<double>(), cancellationToken)
var taskChild = child; .ConfigureAwait(false);
}
tasks.Add(Task.Run(async () => await RefreshChildMetadata(taskChild, refreshOptions, false, innerProgress, cancellationToken).ConfigureAwait(false), cancellationToken));
} numComplete++;
double percent = numComplete;
percent /= count;
percent *= 100;
progress.Report(percent);
} }
await Task.WhenAll(tasks).ConfigureAwait(false);
progress.Report(100); progress.Report(100);
} }