Sign in to follow this  
Followers 0
Function

100% CPU Usage with a relatively simple script

10 posts in this topic

Hello, I'm trying to create some menus for the tray icon in my autoitscript and I've been getting 100% cpu usage running this code, making the menu's non responsive. Can someone help point out the error in my code? Thank you.

CODE
#include <Constants.au3>

Opt("WinTitleMatchMode",2)

Opt("SendKeyDelay", 0)

Opt("SendKeyDownDelay", 0)

Opt("TrayOnEventMode",1)

Opt("TrayMenuMode",1)

$help = TrayCreateItem("&Help")

$seperator1 = TrayCreateItem("")

$windowspy = TrayCreateItem("&Window Spy")

$reload = TrayCreateItem("&Reload This Script")

$edit = TrayCreateItem("&Edit This Script")

$seperator2 = TrayCreateItem("")

$pause = TrayCreateItem("&Pause Script")

$exit = TrayCreateItem("E&xit")

TraySetState()

#cs

HotKeySet("{ESC}", "DoIt")

Func DoIt()

;Some Func

EndFunc

#ce

While 1

$msg = TrayGetMsg()

Select

Case $msg = 0

ContinueLoop

Case $msg = $help

Run (@ScriptDir & "\AutoIt3.chm")

Case $msg = $windowspy

Run (@ScriptDir & "\Au3Info.exe")

Case $msg = $reload

Sleep(100) ;??

Case $msg = $edit

Run ("notepad.exe " & @ScriptFullPath)

Case $msg = $pause

Sleep(100) ;??

Case $msg = $exit

ExitLoop

EndSelect

WEnd

Also if someone could give me a tip how to implement the reload and pause script portions of my code, I'd greatly appreciate it. Thank you

I'm running the latest autoit on windows xp

Share this post


Link to post
Share on other sites



Actually, that fixed it. Thank you. I was originally going to go through the other route of creating tray icon menu's.

Share this post


Link to post
Share on other sites

Actually, that fixed it. Thank you. I was originally going to go through the other route of creating tray icon menu's.

Moved to Support <_<

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

100% CPU Usage is still a bug, no?

Share this post


Link to post
Share on other sites

100% CPU Usage is still a bug, no?

no, why ?

TrayGetMsg() returns @error = 1 because its in event mode and thus isn't doing a 10 ms sleep...

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

As the code stands, it gives me 100% CPU usage. Try it and see if you can replicate this

Share this post


Link to post
Share on other sites

As the code stands, it gives me 100% CPU usage. Try it and see if you can replicate this

I know and have given the answer but will be a bit more detailed:

Normally TrayGetMsg() has a built-in 10 ms sleep to allow other processes to take the CPU, but in your case the TrayGetMsg() errors out due to the Eventmode setting, thus doesn't do the 10ms sleep.

This results in the loop not being paused at all.

Better explanation ?

Jos <_<


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

$msg = 0

It was just doing a loop. Thats what caused the 100% usage for me.

Also what was the Continue loop etc. for. Took it out. Couldn't find a reason. Your exit also didn't work, changed that.

-snip-

Updated a few things. You also needed to get rid of Opt("TrayOnEventMode", 1), and Opt("TrayMenuMode",1). Causing your tray menu not to work.

This should not be needed as explained in my previous post.... <_<

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Okay, thank you jos. I didn't check to just see if that corrected the problem. But in that script above, not deleted.. his exit function didn't work or his tray menu functions.


[font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font]

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