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 线程中调用它,它不会有这么长的延迟。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)