Sign in to follow this  
Followers 0
Maintel

Problem with TrayGetMsn and Sleep

5 posts in this topic

Hi

I have something like this

........
While 1

$msg = TrayGetMsg()
Select
    Case $msg = 0
        ContinueLoop
    Case $msg = $aboutitem
        Msgbox(64, "About", "AKTE Auto Updater v2.1 by Krosik"& @LF & @LF &"www.vw-club.cz")
    Case $msg = $exititem
        ExitLoop
    EndSelect

sleep(200)

WEnd

Without Sleep it take about 80% of processor so I must add Sleep. Problem is, that with Sleep command, when I click on Exit or About in Menu, it take 2-4 seconds :) until this command execute.

Is this natural of Sleep and TrayGetMsg command or it's a bug? How can I have while cycle with monitoring of TrayGetMsg but without draining processor resources?

thanks

Share this post


Link to post
Share on other sites



Even when script is compiled?

You only need a 25ms sleep inn your while, without draining cpu, and lowering the sleep makes the script more responsive.


UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try it by yourself, Sleep in TrayGetMsg loop make significant delays in executing of menu items :)

Because I have in loop $list = WinList() and I'm waiting to showing up of severals windows, I need slow this loop because it use 99% of processor. But then here is the problem with slow reaction.

You can simulate it with this simple code (it's from Help file):

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1); Default tray menu items (Script Paused/Exit) will not be shown.

$settingsitem   = TrayCreateMenu("Settings")
$displayitem    = TrayCreateItem("Display", $settingsitem)
$printeritem    = TrayCreateItem("Printer", $settingsitem)
TrayCreateItem("")
$aboutitem    = TrayCreateItem("About")
TrayCreateItem("")
$exititem      = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(64,"About:","AutoIt3-Tray-sample")
        Case $msg = $exititem
            ExitLoop
    EndSelect
Sleep(200)
WEnd

Exit
Edited by Maintel

Share this post


Link to post
Share on other sites

If you chage your sleep script works like a charm without draining cpu.

#Include <Constants.au3>
#NoTrayIcon

Opt("TrayMenuMode",1)  ; Default tray menu items (Script Paused/Exit) will not be shown.

$settingsitem   = TrayCreateMenu("Settings")
$displayitem    = TrayCreateItem("Display", $settingsitem)
$printeritem    = TrayCreateItem("Printer", $settingsitem)
TrayCreateItem("")
$aboutitem      = TrayCreateItem("About")
TrayCreateItem("")
$exititem       = TrayCreateItem("Exit")

TraySetState()

While 1
    $msg = TrayGetMsg()
    Select
        Case $msg = 0
            ContinueLoop
        Case $msg = $aboutitem
            Msgbox(64,"about:","AutoIt3-Tray-sample")
        Case $msg = $exititem
            ExitLoop
    EndSelect
    
    Sleep(25)
WEnd

Exit

UDF:Crypter a file encrypt / decrypt tool with no need to remember a password again. Based on Caesar cipher using entire ASCII Table.Script's: PixelSearch Helper, quick and simple way to create a PixelSeach.Chatserver - simplified, not so complicated multi-socket server.AutoIT - Firewall, simple example on howto create a firewall with AutoIt.

Share this post


Link to post
Share on other sites

Well yes... I change it to 25....

Anyway I like to know why delay for example 200 (miliseconds) slow down reaction for menu item to 5 seconds? Program's bug or nature of TrayGetMsg?

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