Jump to content

Go faster (more efficient) stripes needed


Recommended Posts

Hello!

The code below is using 10-12% processor utilisation, and uses more and more depending on the number of windows open.

Is there a more efficient way of detecting a new window without checking each one in turn every time?

AIM : - If {there's a new window that we haven't seen before} then {do something} - without using loads of cycles to find out!!

Cheers gurus - you rock!!

Icarus

CODE
While 1

; Get the list of Window titles

$avWinListCurrent = WinList()

For $n = $avWinListCurrent[0][0] To 1 Step -1

; Check has title and visible

If ($avWinListCurrent[$n][0] <> "") And BitAND(WinGetState($avWinListCurrent[$n][1]), 2) Then

; Have we seen this window before?

$fFound = False

For $i = 1 To $avWinListPrevious[0][0]

If $avWinListCurrent[$n][1] = $avWinListPrevious[$i][1] Then

$fFound = True

ExitLoop

EndIf

Next

; No we haven't - its a new Window, let's do something with it.....

If Not $fFound Then

;{do something...blah blah }

Link to comment
Share on other sites

Why not something like this:

$oldList = WinList ()

While 1
    $newList = WinList ()
    If $oldList[0][0] <> $newList[0][0] Then
        MsgBox (0, "", "There is a new window!")        
        $oldList = $newList
    EndIf
WEnd
Link to comment
Share on other sites

Thanks for the quick response!!

I've tried the SLEEP (nn) in various places, but what happens then is that I miss some windows.

As I'm trying to catch error messages, they may only be on screen for a couple of seconds...

Brett - I'll try and incorporate your idea - nice one - and report back...

Any other suggestions..?? Is this the best way??

Link to comment
Share on other sites

A Sleep (100) before the WEND causes processor utilisation of ~50% on a 20-window session....

Its important to get the balance of checking (almost) all the time quickly, whilst not using much CPU, hence the need for a quick way to check for new windows.

Off to try Brett's suggestion..

Much appreciated..

Link to comment
Share on other sites

Using both suggestions (global array check and sleep timer before the WEND) the code now runs at ZERO %!!!

It peaks at 1.5% CPU for one second when it detects a new Window, then goes back to zero %.

When it does the work it needs (logging etc) it peaks a little higher, but essentially its fixed!!!

I did say you guru guys are awesome...!!

Love it!

Love the app, love coding, and love these forums!!!!

Thank you a million times over people..!!

Icarus

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...