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.