Skip to content

Commit b40e30a

Browse files
committed
- set file operations to single thread by default
- add multithreading to MediaInfoProvider, related changes - don't disable labels for UI during generation
1 parent b5012d1 commit b40e30a

File tree

4 files changed

+41
-28
lines changed

4 files changed

+41
-28
lines changed

QuickList/Application/Configuration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ internal static Configuration Parse(string iniFile)
8181
ForceShellMedia = IniReader.ReadValue("QuickList", "ForceShellMedia", iniFile, "0") == "1"
8282
};
8383

84-
int.TryParse(IniReader.ReadValue("QuickList", "FileReaderParallelism", "0"), out var fileReaderParallelism);
85-
configuration.FileReaderParallelism = fileReaderParallelism <= 0 ? Environment.ProcessorCount : fileReaderParallelism;
84+
int.TryParse(IniReader.ReadValue("QuickList", "FileReaderParallelism", "1"), out var fileReaderParallelism);
85+
configuration.FileReaderParallelism = fileReaderParallelism;
8686

8787
var dirsFile = IniReader.ReadValue("ListMagic", "DirsFile", iniFile);
8888

QuickList/Application/MediaCache.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.IO;
45
using System.Linq;
@@ -10,7 +11,7 @@ namespace Sander.QuickList.Application
1011
internal sealed class MediaCache
1112
{
1213
private readonly Configuration _configuration;
13-
private readonly List<Entry> _newCache = new List<Entry>();
14+
private readonly ConcurrentBag<Entry> _newCache = new ConcurrentBag<Entry>();
1415
private Dictionary<string, Entry> _mediaCache;
1516

1617

QuickList/Application/MediaInfoProvider.cs

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ internal Task AddMediaInfo(List<Entry> entries)
6060
timer.Elapsed += (sender, args) => _configuration.Status = Status.Get("Getting media info", percentage);
6161
}
6262

63-
entries.ForEach(entry =>
63+
entries
64+
.AsParallel()
65+
.WithDegreeOfParallelism(_configuration.FileReaderParallelism)
66+
.WithExecutionMode(ParallelExecutionMode.ForceParallelism)
67+
//.ForEach(entry =>
68+
.ForAll(entry =>
6469
{
6570

6671
percentage += step;
@@ -119,36 +124,40 @@ private bool GetTagLibInfo(Entry entry)
119124
catch (Exception e)
120125
{
121126
Trace.WriteLine($"Problem getting media info for \"{entry.Fullname}\". Error:\r\n{e.Source}: {e.Message}");
122-
return false;
127+
return false;
123128
}
124129
}
125130

126131

127132
[MethodImpl(MethodImplOptions.AggressiveInlining)]
128-
private static void GetShellInfo(Entry entry)
133+
private void GetShellInfo(Entry entry)
129134
{
130-
using (var shellFile = ShellFile.FromFilePath(entry.Fullname))
135+
lock (this)
131136
{
132-
var durationNs = shellFile.Properties.System.Media.Duration.Value;
133-
if (durationNs == null || durationNs == 0)
134-
return;
135-
136-
var duration = TimeSpan.FromMilliseconds(durationNs.Value * 0.0001);
137-
//cheap video detection
138-
if (shellFile.Properties.System.Video.FrameWidth.Value.HasValue)
137+
using (var shellFile = ShellFile.FromFilePath(entry.Fullname))
139138
{
140-
var video = shellFile.Properties.System.Video;
141-
entry.MediaInfo = FormatVideo(duration,
142-
(int)(video.FrameWidth.Value ?? 0),
143-
(int)(video.FrameHeight.Value ?? 0),
144-
video.FrameRate.Value / 1000);
145-
}
146-
else if (shellFile.Properties.System.Audio.ChannelCount.Value.HasValue)
147-
{
148-
entry.MediaInfo = FormatAudio(duration,
149-
(int)((shellFile.Properties.System.Audio.EncodingBitrate.Value ?? 0) / 1000),
150-
(shellFile.Properties.System.Audio.SampleRate.Value ?? 0) / 1000f,
151-
(int)shellFile.Properties.System.Audio.ChannelCount.Value.Value);
139+
var durationNs = shellFile.Properties.System.Media.Duration.Value;
140+
if (durationNs == null || durationNs == 0)
141+
return;
142+
143+
var duration = TimeSpan.FromMilliseconds(durationNs.Value * 0.0001);
144+
//cheap video detection
145+
if (shellFile.Properties.System.Video.FrameWidth.Value.HasValue)
146+
{
147+
var video = shellFile.Properties.System.Video;
148+
entry.MediaInfo = FormatVideo(duration,
149+
(int)(video.FrameWidth.Value ?? 0),
150+
(int)(video.FrameHeight.Value ?? 0),
151+
video.FrameRate.Value / 1000);
152+
}
153+
else if (shellFile.Properties.System.Audio.ChannelCount.Value.HasValue)
154+
{
155+
entry.MediaInfo = FormatAudio(duration,
156+
(int)((shellFile.Properties.System.Audio.EncodingBitrate.Value ?? 0) / 1000),
157+
(shellFile.Properties.System.Audio.SampleRate.Value ?? 0) / 1000f,
158+
(int)shellFile.Properties.System.Audio.ChannelCount.Value.Value);
159+
160+
}
152161
}
153162
}
154163
}

QuickList/UI/MainForm.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Diagnostics;
33
using System.IO;
44
using System.Reflection;
5-
using System.Threading;
65
using System.Threading.Tasks;
76
using System.Windows.Forms;
87
using Sander.QuickList.Application;
@@ -73,7 +72,11 @@ private void CurrentListLabel_Click(object sender, EventArgs e)
7372

7473
private void Disable(Control control)
7574
{
76-
control.Enabled = false;
75+
if (control is Label || control.Name == "CurrentListPanel")
76+
return;
77+
78+
if (control != this)
79+
control.Enabled = false;
7780
foreach (Control child in control.Controls)
7881
{
7982
Disable(child);

0 commit comments

Comments
 (0)