From de038ac029f5c5a8203df8e50083608ad30feb36 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 19 Apr 2013 16:43:09 -0400 Subject: [PATCH] faster progress reporting during library scan --- MediaBrowser.Controller/Entities/Folder.cs | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 7253825a8c..2b924ea884 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -653,7 +653,7 @@ namespace MediaBrowser.Controller.Entities { var list = children.ToList(); - var percentages = new ConcurrentDictionary(list.Select(i => new KeyValuePair(i.Item1.Id, 0))); + var percentages = new Dictionary(); var tasks = new List(); @@ -695,24 +695,30 @@ namespace MediaBrowser.Controller.Entities innerProgress.RegisterAction(p => { - percentages.TryUpdate(child.Id, p / 100, percentages[child.Id]); + lock (percentages) + { + percentages[child.Id] = p/100; - var percent = percentages.Values.Sum(); - percent /= list.Count; + var percent = percentages.Values.Sum(); + percent /= list.Count; - progress.Report((90 * percent) + 10); + progress.Report((90 * percent) + 10); + } }); await ((Folder)child).ValidateChildren(innerProgress, cancellationToken, recursive).ConfigureAwait(false); } else { - percentages.TryUpdate(child.Id, 1, percentages[child.Id]); + lock (percentages) + { + percentages[child.Id] = 1; - var percent = percentages.Values.Sum(); - percent /= list.Count; + var percent = percentages.Values.Sum(); + percent /= list.Count; - progress.Report((90 * percent) + 10); + progress.Report((90 * percent) + 10); + } } })); }