I use Directory.GetFilesto give me mp3 files, and I would like to fill in the ListBoxresults, but instead of stopping the program while it goes through, can I get it to search and fill ListBoxup, since it will receive mp3 files?
so I use the following (and he cannot add them in time, he adds them all at once, when this is done)
private List<string> Getmp3sFromFolders(string folder)
{
List<string> fileArray = new List<string>();
try
{
DirectoryInfo dir = new DirectoryInfo(folder);
var files = dir.EnumerateFiles("*.mp3");
foreach (var file in files)
{
fileArray.Add(file.FullName);
Dispatcher.BeginInvoke(_AddMP3ToListbox, file.Name);
}
var directories = dir.EnumerateDirectories();
foreach (var subdir in directories)
{
fileArray.AddRange(Getmp3sFromFolders(subdir.FullName));
}
}
catch
{
}
return fileArray;
}
I added _AddMP3ToListbox = AddMP3ToListbox
he really adds mp3 to the list, but he does it right away, and not right away, as soon as he finds it. how can i fix this?
source
share