diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-24 11:08:51 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-24 11:08:51 -0400 |
| commit | b49764dbaafbbf11b6308ec675355696b9e58379 (patch) | |
| tree | 58677308bf98c95f1982a84eb403a01241f0a692 /MediaBrowser.Server.Implementations/Library/LibraryManager.cs | |
| parent | 14c464c28a3b9cac207ef741711e31cef1c15378 (diff) | |
fixes #555 - Have clients report seek and queuing capabilities
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library/LibraryManager.cs')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Library/LibraryManager.cs | 54 |
1 files changed, 16 insertions, 38 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index a5b792726..1bc3f1094 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -829,10 +829,6 @@ namespace MediaBrowser.Server.Implementations.Library /// <returns>Task.</returns> public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress) { - const int maxTasks = 3; - - var tasks = new List<Task>(); - var people = RootFolder.RecursiveChildren .SelectMany(c => c.People) .DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase) @@ -842,47 +838,27 @@ namespace MediaBrowser.Server.Implementations.Library foreach (var person in people) { - if (tasks.Count > maxTasks) + cancellationToken.ThrowIfCancellationRequested(); + + try { - await Task.WhenAll(tasks).ConfigureAwait(false); - tasks.Clear(); + var item = GetPerson(person.Name); - // Safe cancellation point, when there are no pending tasks - cancellationToken.ThrowIfCancellationRequested(); + await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); } - - // Avoid accessing the foreach variable within the closure - var currentPerson = person; - - tasks.Add(Task.Run(async () => + catch (IOException ex) { - cancellationToken.ThrowIfCancellationRequested(); - - try - { - var item = GetPerson(currentPerson.Name); - - await item.RefreshMetadata(cancellationToken).ConfigureAwait(false); - } - catch (IOException ex) - { - _logger.ErrorException("Error validating IBN entry {0}", ex, currentPerson.Name); - } + _logger.ErrorException("Error validating IBN entry {0}", ex, person.Name); + } - // Update progress - lock (progress) - { - numComplete++; - double percent = numComplete; - percent /= people.Count; + // Update progress + numComplete++; + double percent = numComplete; + percent /= people.Count; - progress.Report(100 * percent); - } - })); + progress.Report(100 * percent); } - await Task.WhenAll(tasks).ConfigureAwait(false); - progress.Report(100); _logger.Info("People validation complete"); @@ -956,7 +932,9 @@ namespace MediaBrowser.Server.Implementations.Library public Task ValidateMediaLibrary(IProgress<double> progress, CancellationToken cancellationToken) { // Just run the scheduled task so that the user can see it - return Task.Run(() => _taskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>()); + _taskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>(); + + return Task.FromResult(true); } /// <summary> |
