0

When I try to iterate the file explorer windows in C#.

It takes 7 - 15 seconds to execute the Windows method.

In powershell, it takes less than a second.

What is causing such a long delay?

        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);
        }

Edit: After more testing. I found that the long call happens when I run this in protected override void OnStartup(StartupEventArgs e) of my WPF application.

However, it doesn't have this long delay if I call it in a STA thread that runs 5 seconds after the application startup.

John
  • 5,942
  • 3
  • 42
  • 79
  • What is `Shell32`, exactly? What library/namespace? – Dai Aug 01 '21 at 23:40
  • Also, why are you using `dynamic` with what appears to be a strongly-typed library? – Dai Aug 01 '21 at 23:41
  • Microsoft Shell Controls And Automation Library. It returns a com object with dynamic members. – John Aug 01 '21 at 23:43
  • Process Monitor (ProcMon) might be able to reveal what is causing the slowness. I suspect it may have to do with Internet Explorer startup. Can you post your PowerShell code for comparison purposes? – leeharvey1 Aug 08 '21 at 15:37

0 Answers0