C# 为什么 Shell32.Shell.Windows() 这么慢?

当我尝试在 C# 中迭代​​文件资源管理器窗口时。

执行 Windows 方法需要 7 - 15 秒。

在 powershell 中,只需不到一秒钟。

是什么导致了这么长时间的延迟?

        Shell32.Shell o = new Shell32.Shell();

        // This takes 7 - 15 seconds to execute
        dynamic allWindows = o.Windows();

        for (int i = 0; i < allWindows.count; i++)
        {
            dynamic item = allWindows[i];

            string location = item.LocationURL as string;

            Console.log("Full path",location);
        }

编辑: 经过更多的测试。我发现当我在 WPF 应用程序的 protected override void OnStartup(StartupEventArgs e) 中运行时会发生长时间调用。

但是,如果我在应用程序启动 5 秒后运行的 STA 线程中调用它,它不会有这么长的延迟。

rockyhmrr 回答:C# 为什么 Shell32.Shell.Windows() 这么慢?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/209.html

大家都在问