EnumWindows + Slow Thread Start

  • Thread starter Thread starter Sean Dudley
  • Start date Start date
S

Sean Dudley

I am currently enumerating windows via the EnumWindows API.

I noticed that for some reason the very first time I call my enumwindows
routine (inside or outside of a thread) it seems to be very slow. But
subsequent times in the same running instance the calls are super quick.

What might cause an API call like this to be very, very slow the first time
it is called and fast the rest of the times?
 
Sean,

It could be that initializing the P/Invoke layer is taking all the time,
as well as finding the dll to load, and then setting up the call. Of
course, on subsequent calls, the initialization of the P/Invoke layer is not
needed, and I am sure that a thunk has already been created to call into the
function (since you did it once already).

Hope this helps.
 
What do you call "very, very slow "? How did you measure this?

I have measured the following:
1st run 720µsec
2nd run: 116µsec.
using the following signature:
[DllImport("user32"), SuppressUnmanagedCodeSecurityAttribute]
public static extern int EnumWindows(CallBack x, int y);

and a static Callback that just returns true.

Willy.
 
It's taking about ten seconds the first time. I'll get together an example.

Willy Denoyette said:
What do you call "very, very slow "? How did you measure this?

I have measured the following:
1st run 720µsec
2nd run: 116µsec.
using the following signature:
[DllImport("user32"), SuppressUnmanagedCodeSecurityAttribute]
public static extern int EnumWindows(CallBack x, int y);

and a static Callback that just returns true.

Willy.


Sean Dudley said:
I am currently enumerating windows via the EnumWindows API.

I noticed that for some reason the very first time I call my enumwindows
routine (inside or outside of a thread) it seems to be very slow. But
subsequent times in the same running instance the calls are super quick.

What might cause an API call like this to be very, very slow the first time
it is called and fast the rest of the times?
 
I am an idiot. It was my ExtractWindowIcon routine inside the callback
causing issues. I was doing some very dumb stuff in there. Sorry for
wasting your time, though you guys did help alot!

-Sean
 
Back
Top