473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

EnumWindows + Slow Thread Start

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?
Nov 15 '05 #1
5 2894
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Sean Dudley" <du*****@uwplatt.edu> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
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?

Nov 15 '05 #2
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" <du*****@uwplatt.edu> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
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?

Nov 15 '05 #3
It's taking about ten seconds the first time. I'll get together an example.

"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:eW**************@TK2MSFTNGP12.phx.gbl...
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" <du*****@uwplatt.edu> wrote in message
news:uN**************@TK2MSFTNGP11.phx.gbl...
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?


Nov 15 '05 #4
What version of the Framework and OS are you running this on?

Willy.

"Sean Dudley" <du*****@uwplatt.edu> wrote in message
news:uX*************@TK2MSFTNGP11.phx.gbl...
It's taking about ten seconds the first time. I'll get together an example.

Nov 15 '05 #5
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
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:eA**************@TK2MSFTNGP12.phx.gbl...
What version of the Framework and OS are you running this on?

Willy.

"Sean Dudley" <du*****@uwplatt.edu> wrote in message
news:uX*************@TK2MSFTNGP11.phx.gbl...
It's taking about ten seconds the first time. I'll get together an

example.


Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim W | last post by:
This is a cross-post from the .NET group since it looks like it may not be ..NET. New information since the original post is that is the wireless network is enabled and connected the socket...
2
by: Martin Baker | last post by:
I have an activeX control which I am calling from a C# program, this works fine. I now want to call the activeX control from a seperate thread, this works but is very slow. This is far too slow...
11
by: Wayne | last post by:
I have some code written in delphi that uses EnumWindows, I would like to begin to translate this code to C#. Is there a built in EnumWindows call in Csharp? or do I have to import the API and use...
22
by: Rudy Ray Moore | last post by:
Why is "Visual Studio .net 2003 7.1 c++" so much slower than VS6 at linking? It looks like "Visual Studio .net 2003 7.1 c++" doesn't even do incremental linking! I make one very minor change in...
5
by: Jim W | last post by:
I have an ASP.NET app that has very slow connect times using TCPClient, or the Socket class, or even calling a COM object that uses C socket calls on certain similar XP SP2 boxes. On those...
3
by: qilinw | last post by:
In a winform I want to display database records using datagrid, with dataset for a couple of thousands records it seems very slow. I have read an article in group...
5
by: PH | last post by:
Hi guys; I got a single processor computer, running an application that launches 2 threads. Each of these threads listens for incoming connections in a specific port, so there is a Loop ....
0
by: Buddy Home | last post by:
There is two examples of code. Example 1. Send and Receive within the same process. Put this code in a console app called SendAndReceive and run the code. using System; using...
1
by: =?Utf-8?B?VHJlY2l1cw==?= | last post by:
Hello, Newsgroupians: I've a question regarding the Win32 function EnumWindows. First, the prototype for EnumWindows is as follows... BOOL EnumWindows(WNDENUMPROC lpEnumFunc, LPARAM lParam) ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.