Luaca
Luaca

Reputation:

C# - end/finished "event" of a recursive function?

Lets assume the following function:

private void ParseFolder(string strFolder)
{
    foreach (string currentFolder in Directory.GetDirectories(strFolder))
    ParseFolder(strFolder);
}

Now we start our recursive loop with:

ParseFolder("C:\");

Is there a way to be notified when this recusrive loop ends (= all directories have been parsed)?

Upvotes: 0

Views: 442

Answers (2)

Cᴏʀʏ
Cᴏʀʏ

Reputation: 107606

private void DoWork()
{
     ParseFolder("C:\\");
     // Once you get here, the work is done.
}


private void ParseFolder(string strFolder)
{
    foreach (string currentFolder in Directory.GetDirectories(strFolder))
    ParseFolder(strFolder);
}

Upvotes: 1

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422242

Yes, just add a method call after it:

ParseFolder("C:\\"); // You need to escape \
Notify();

Upvotes: 1

Related Questions