Jump to content

Eats up CPU (creating many GUIs)


Recommended Posts

Hi,

why does this example eat up CPU before 300 GUIs?

#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include<WinAPI.au3>
HotKeySet('{F1}', '_end')
Global $i = 0

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case Else
    EndSwitch
    Sleep(50)
;~     _setPixel(_WinAPI_GetMousePosX(), _WinAPI_GetMousePosY())
    _setPixel(2*$i, 2*$i)
    ToolTip('GUIs: ' & $i, 0, 0)
WEnd

Func _setPixel($left, $top, $width = 5, $height = 5, $color = 0x00FF00)
    GUICreate("", $width, $height, $left, $top, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    GUISetBkColor($color)
    GUISetState(@SW_SHOW)
    $i += 1
    Return 1
EndFunc   ;==>_setPixel

Func _end()
    Exit (0)
EndFunc   ;==>_end

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Did you post a suggestion or do have to read between the lines to get the solution? :)

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

The other guy posted something...like: "It's the GUI doing it...?"

Well, my only suggestion is to find that function called: ReduceCPU and use Adlibenable() to keep it going, that might lower the CPU usage...Cool scirpt though

Link to comment
Share on other sites

With this For loop, it doesn't seem to peter out until around 500. Xeno's posted code stopped at 170-ish, but it barely used any ram.

#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include<WinAPI.au3>
HotKeySet('{F1}', '_end')


For $i = 1 to 1000 
    _setPixel($i, $i)
    ToolTip('GUIs: ' & $i, 0, 0)
Next

Func _setPixel($left, $top, $width = 5, $height = 5, $color = 0x00FF00)
    GUICreate("", $width, $height, $left, $top, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
    GUISetBkColor($color)
    GUISetState(@SW_SHOW)
    $i += 1
    Return 1
EndFunc   ;==>_setPixel

Func _end()
    Exit (0)
EndFunc   ;==>_end
Link to comment
Share on other sites

Xenobiologist code didn't stop working or anything for me, it went above 500 GUI's before it started to show any real cpu usage, still only around ~30% though. But when I removed the Sleep(50), it went to ~750 GUI's fairly quickly, but then came to a crawl.. like 5 gui's per second... and cpu usage around 50-70%

Your code Senton-Bomb is faster, but that's only because you're doing the same as Step 2 would do in a For loop(notice you still have $i += 1 in the _setPixel function).

doh.

Funny thing is that when I run this code, I hear a buzz in my subwoofers. :)

Edited by FreeFry
Link to comment
Share on other sites

Hi,

tahnks for testing guys. But is there an explanation why the script eats up CPU at a special point?

I thought it should run until 1024 GUI controls are created.

Bug or am I'm doing something wrong?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Your script runs fine for me, it just comes to a crawl after some time, and uses a really high amount of cpu power...

And I don't know, maybe it's kinda self explanatory that it starts lagging with such a huge amount of GUI's...

Link to comment
Share on other sites

Your script runs fine for me, it just comes to a crawl after some time, and uses a really high amount of cpu power...

And I don't know, maybe it's kinda self explanatory that it starts lagging with such a huge amount of GUI's...

How many GUIs can you create? Using this line

;~ _setPixel(_WinAPI_GetMousePosX(), _WinAPI_GetMousePosY()) in lieu of this _setPixel(2*$i, 2*$i) ?

Okay, maybe you got a faster CPU. There is still the sleep in the loop, so why should eat use ~ 100 % CPU? Just to keep in mind there are many GUIs out there?

I'll give it a try without the guicreating-loop / or using a hotkey to jump out of the creating function to a

while 1

Sleep(1000)

wend

function to see whether it still eats up my CPU then.

Good night from Germany!

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

I ran it, I got to 750 GUI's before it really slowed down to like 3 GUI's a second, and CPU shows as 50%(I'm betting it's 100% as it's a dual core cpu(P4, 3.6GHz))

Edit:

I changed the Sleep(50) to 1 so I wouldn't have to wait. :)

Edited by FreeFry
Link to comment
Share on other sites

Hi,

hmmh I cannot explain.

I guess this is a bug. Autoit uses 100 % of CPU after reaching a "max" of GUIs. On my PC it is ~ 297 GUIs.

Even jumping into the idle func it uses 100 % till then.

HotKeySet('{ESC}', '_end')
HotKeySet('1', '_create')
HotKeySet('2', '_idle')

_create()

Func _create()
    For $i = 0 To 1000
        GUICreate($i, Random(10, 100, 1), Random(10, 50, 1), _
                Random(0, @DesktopWidth - 110, 1), Random(0, @DesktopHeight - 60, 1), _
                $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
        GUISetState()
        ToolTip($i, 0, 0)
        Sleep(5)
    Next
EndFunc   ;==>_create

Func _idle()
    ConsoleWrite('! idle' & @CRLF)
    While 1
        Sleep(10000)
    WEnd
EndFunc   ;==>_idle

Func _end()
    Exit (0)
EndFunc   ;==>_end

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Weird stuff. :)

Yes!, because I cannot see why many GUIs should eat the CPU in lieu of RAM. And how to get 1024 GUIs as stated in the helpfile?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Yes!, because I cannot see why many GUIs should eat the CPU in lieu of RAM. And how to get 1024 GUIs as stated in the helpfile?

Mega

Just tried this on my PC 3.2Mhz Pentium4 HT and it flies along until about 170 GUIs have been created when it starts to slow down and finally stalls at 185 GUIs with 1 CPU tread maxed out at 50%

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

Hi, :)

I did a BugReport, so probably we'll get an answer soon.

#include<WindowsConstants.au3>

;~ Maximum number of GUI windows: No limit ????

HotKeySet('{ESC}', '_end')
HotKeySet('1', '_create')
HotKeySet('2', '_idle')

_create()

Func _create()
    For $i = 0 To 1000
        GUICreate('', Random(10, 100, 1), Random(10, 50, 1), _
                Random(0, @DesktopWidth - 110, 1), Random(0, @DesktopHeight - 60, 1), _
                $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST))
        GUISetBkColor(_randomColor())
        GUISetState()
        ToolTip($i, 0, 0)
        Sleep(5)
    Next
EndFunc   ;==>_create

Func _idle()
    ConsoleWrite('! idle' & @CRLF)
    While 1
        Sleep(10000)
    WEnd
EndFunc   ;==>_idle

Func _randomColor()
    Return Random(0x000000, 0xFFFFFF)
EndFunc   ;==>_randomColor

Func _end()
    Exit (0)
EndFunc   ;==>_end

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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...