Sign in to follow this  
Followers 0
Dalex

Script eating up memory

7 posts in this topic

#1 ·  Posted (edited)

I want to create a script the will check if several programs exist on a machine then display a small colored label beside another label that contains the name of the app. It checks if a certain file exists, if it does then the colored label will be green, if it does not exist the colored label will flash red then yellow until the script is closed.

I have all of this working except for the fact that every time it goes through the loop of IF statements I think it is creating yellow and red labels on top of the existing ones which causes it to continually eat up system memory. Does any one have any better ideas of how I could create a blinking label that would simulate an LED blinking? Or fix it so it would destroy one label before it creates the new one?

It needs to be able to blink for several different $Variables, I have only included one Item in the list for simplicity, but you could test this script by removing a letter out of the file name in the "If FileExists" statement. Must also have it in a file with "Header.au3", and "GUIConstants.au3" before testing or compiling.

#include "GUIConstants.au3"Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
;----------------------------------------------------------------------------------------------------------------------------------Dim $MainWindow 
Dim $MainLabel
Dim $color
Dim $font   = "Comic Sans MS"
Dim $Red    = 0xff00000
Dim $Green  = 0x00ff7f
Dim $Yellow = 0xffff00Dim $netFrame1
Dim $Net1
;----------------------------------------------------------------------------------------------------------------------------------
;NetFramework Check
If FileExists("C:\WINDOWS\icrosoft.NET") Then
 $netFrame1 = $Green 
Else
 $netFrame1 = $Red
EndIf$MainWindow = GUICreate("TEST", 600, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetState(@SW_SHOW)
GUICtrlCreateLabel("TEST", 270,10,150,30)
GUICtrlSetFont (-1,16, 800, 4, $font)
;----------------------------------------------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------------------------------------
;----------------------------------------------------------------------------------------------------------------------------------
;.NET Framework Create
GUICtrlCreateLabel(".Net Framework 1.1", 20, 70, 117)
;Starts the Loop
While 1;----------------------------------------------------------------------------------------------------------------------------------$Net1 = GUICtrlCreateLabel("", 5,73,10,8)
GUICtrlSetBkColor(-1,$netFrame1) ; Color
;----------------------------------------------------------------------------------------------------------------------------------
If  $netFrame1 = $Red Then
 GUICtrlDelete($Net1)
 $Net1 = GUICtrlCreateLabel("", 5,73,10,8)
 $netFrame1 = $Yellow
 GUICtrlSetBkColor(-1,$netFrame1) ; Color
ElseIf $netFrame1 = $Yellow Then
    GUICtrlDelete($Net1)
    $Net1 = GUICtrlCreateLabel("", 5,73,10,8)
    $netFrame1 = $Red
    GUICtrlSetBkColor(-1,$netFrame1) ; Color
    
EndIf
 
 Sleep(1000)  
WEndFunc CLOSEClicked()
 Exit
EndFunc
Edited by Dalex

[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites



Well, as you said, the labels are created every time the script goes through the loop, so my question to you then is :

Why can't you just create the labels before the loop like you did with the TEST-label ?

Share this post


Link to post
Share on other sites

i dont know what happens in Header.au3

but you are creating a new label every second

you should not create them, just change it.

and if you really want to create a new one every second you should delete the old one.


CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

Share this post


Link to post
Share on other sites

i dont know what happens in Header.au3

but you are creating a new label every second

you should not create them, just change it.

and if you really want to create a new one every second you should delete the old one.

Thank's for the replys, The effect I am trying to get is; if the file is there it will look like a green LED, If the file is not there I want it to look like an LED blinking red then yellow. I am trying to figure out the best way to do it. I took your advice and deleted the label before creating a new one (don't know why I couldn't figure out how to do that before, been working on this for a week), I believe that will work but I don't think that it is the cleanest most efficient way to do it.

(I am an autoit3 noob, with no past programming experience) I may not even need to include the "Header.au3".

In your post you said change it, instead of creating a new one. Can you give me a hint of how to "Change it", I am not sure where to look in the help file.

After I post this reply I am going to edit my first post with the new code so you can see my changes.

Thanks again for you help.

Autoit Rocks!


[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites

Well, as you said, the labels are created every time the script goes through the loop, so my question to you then is :

Why can't you just create the labels before the loop like you did with the TEST-label ?

I took your advice also Helge and created the application label that will never change before the loop.

Thanks.

But it look like I spoke to soon, the green label works fine and does not chew on the memory, but if the file does not exist then the red and yellow label are never created for some reason.


[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
Share on other sites

if i had to guess i would guess you want it that way:

#include "GUIConstants.au3"

Opt("GUIOnEventMode", 1)

Dim $MainWindow, $MainLabel, $color
Dim $font = "Comic Sans MS"
Dim $Red = 0xff00000, $Green = 0x00ff7f, $Yellow = 0xffff00
Dim $netFrame1, $Net1, $fSwitch = True

$MainWindow = GUICreate("TEST", 600, 400)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUICtrlCreateLabel("TEST", 270, 10, 150, 30)
GUICtrlSetFont(-1, 16, 800, 4, $font)
GUICtrlCreateLabel(".Net Framework 1.1", 20, 70, 117)
$Net1 = GUICtrlCreateLabel("", 5, 73, 10, 8)
GUISetState(@SW_SHOW)

While 1
    If FileExists("C:\WINDOWS\Microsoft.NET") Then
        GUICtrlSetBkColor($Net1, $Green)
    ElseIf $fSwitch Then
        GUICtrlSetBkColor($Net1, $Red)
        $fSwitch = False
    Else
        GUICtrlSetBkColor($Net1, $Yellow)
        $fSwitch = True
    EndIf
    Sleep(1000)
WEnd
Func CLOSEClicked()
    Exit
EndFunc


CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

Share this post


Link to post
Share on other sites

That is awesome piccaso!

(BTW, I got my original working and edited the first post again)

Yours looks alot more high speed, low drag though.

Maybe I will try to merg your example with mine so that it doesn't have to check if the file exist every loop.

Thank you for your time.........


[size="2"][u]Beer is living proof that God loves us and wants us to be happy.-- Ben Franklin[/u][/size]

Share this post


Link to post
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
Sign in to follow this  
Followers 0