I want to read bulk audio file's tags faster. currently i am able to store 5000 audio files info to struct list in about 7 seconds.
issue is when i select folder having 20,000 or 40,000 files the app keeps on running and doesn't notify that the process is done. whereas when it reads 5,000 files it shows the message box prompting "Done loading files 5000" in 7 seconds.
Here is my code:
public struct SongInfoStruct
{
public string Key;
public string Value;
public string Artist;
public double Duration;
public string Comments;
public string Album;
public string Missing;
};
public async Task<SongInfoStruct> GetSongInfo(string url)
{
var songinfo = (dynamic)null;
var tagFile = TagLib.File.Create(url);
var songName = (dynamic)null;
var artist = (dynamic)null;
var album = (dynamic)null;
var comments = (dynamic)null;
var duration = (dynamic)null;
await Task.Run(() =>
{
songName = tagFile.Tag.Title;
artist = tagFile.Tag.FirstPerformer;
album = tagFile.Tag.Album;
comments = tagFile.Tag.Comment;
duration = tagFile.Properties.Duration.TotalSeconds;
});
return songinfo = new SongInfoStruct
{
Key = url,
Value = songName,
Artist = artist,
Duration = duration,
Comments = comments,
Album = album,
Missing = " "
};
}
public async Task<List<SongInfoStruct>> ReadPathFromSource(string Source)
{
var files = Directory.EnumerateFiles(Source, "*",
SearchOption.AllDirectories).Where(s => s.EndsWith(".mp3") ||
s.EndsWith(".m4a"));
int length = files.Count();
var listpaths = new List<SongInfoStruct>(length);
listpaths.Clear();
foreach (string PathsClickSong_temp in files)
{
var item = await GetSongInfo(PathsClickSong_temp);
await Task.Run(() =>
{
listpaths.Add(item);
});
}
MessageBox.Show("Done loading files "+ listpaths.Count.ToString());
return listpaths;
}