C# - 结束/完成“事件”递归函数?

发布于 2024-08-06 08:34:06 字数 299 浏览 1 评论 0原文

让我们假设以下函数:

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

现在我们开始递归循环:

ParseFolder("C:\");

当这个递归循环结束时(=所有目录都已解析),是否有办法得到通知?

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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

方圜几里 2024-08-13 08:34:06

是的,只需在其后面添加一个方法调用即可:

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

Yes, just add a method call after it:

ParseFolder("C:\\"); // You need to escape \
Notify();
橘虞初梦 2024-08-13 08:34:06
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);
}
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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文