我刚刚完成了这种递归方法:
/// <summary>
/// Recursively process a given directory and add its file to Library.xml
/// </summary>
/// <param name="sourceDir">Source directory</param>
public void ProcessDir(string sourceDir)
{
string[] fileEntries = Directory.GetFiles(sourceDir, "*.mp3");
foreach (string fileName in fileEntries)
{
Song newSong = new Song();
newSong.ArtistName = "test artist";
newSong.AlbumName = "test album";
newSong.Name = "test song title";
newSong.Length = 1234;
newSong.FileName = fileName;
songsCollection.Songs.Add(newSong);
}
string[] subdirEntries = Directory.GetDirectories(sourceDir);
foreach (string subdir in subdirEntries)
{
if ((File.GetAttributes(subdir) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
{
ProcessDir(subdir);
}
}
}
一切都按预期工作,我唯一的问题是:我怎么知道该方法何时完成执行? .NET中是否有专门用于此目的的东西?
最佳答案
.NET中没有什么特别的可以告诉您的...基本上,在递归结束之后,对ProcessDir的第一次调用将返回。
关于c# - 如何检查递归方法是否已结束?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4936539/