Skip to content

Commit

Permalink
Test DoFindFiles as Task, maybe faster... (reverted from commit 091cb83)
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Sep 27, 2016
1 parent 091cb83 commit d136935
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions SimpleMusicPlayer/SimpleMusicPlayer/Core/FileSearchWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public async Task<IEnumerable<IMediaFile>> StartSearchAsync(IList filesOrDirsCol
foreach (var rawDir in orderedDirs.TakeWhile(rawDir => !token.IsCancellationRequested))
{
this.DoFindFiles(token, rawDir, results).ConfigureAwait(false);
this.DoFindFiles(token, rawDir, results);
}
return results;
Expand Down Expand Up @@ -124,28 +124,25 @@ private IEnumerable<string> GetSubFolders(CancellationToken token, string source
return directories;
}

private async Task DoFindFiles(CancellationToken token, string dir, ConcurrentQueue<IMediaFile> results)
private void DoFindFiles(CancellationToken token, string dir, ConcurrentQueue<IMediaFile> results)
{
await Task.Run(() =>
try
{
try
var allFiles = QuickIODirectory.EnumerateFiles(dir, "*", SearchOption.TopDirectoryOnly)
.Where(f => this.IsAudioFile(f.Name));
foreach (var file in allFiles.TakeWhile(rawDir => !token.IsCancellationRequested))
{
var allFiles = QuickIODirectory.EnumerateFiles(dir, "*", SearchOption.TopDirectoryOnly)
.Where(f => this.IsAudioFile(f.Name));
foreach (var file in allFiles.TakeWhile(rawDir => !token.IsCancellationRequested))
var mf = this.GetMediaFile(file.FullName);
if (mf != null)
{
var mf = this.GetMediaFile(file.FullName);
if (mf != null)
{
results.Enqueue(mf);
}
results.Enqueue(mf);
}
}
catch (Exception exception)
{
this.Log().ErrorException("EnumerateFiles", exception);
}
}, token);
}
catch (Exception exception)
{
this.Log().ErrorException("EnumerateFiles", exception);
}
}

private IMediaFile GetMediaFile(string fileName)
Expand Down

0 comments on commit d136935

Please sign in to comment.