@@ -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 }
0 commit comments