kpu Posted February 3, 2006 Share Posted February 3, 2006 I'm working a a program that uses the tray menu to log program information. My question is how do I make my script not take up processor time and still work correclty. Here's my basic code: Program waits until window is active ($Window) and crates a traymenu item for tracking. I'm sure some of you will think this is weird, wrong, ... etc. #include <Array.au3> #include <Date.au3> #Include <Constants.au3> #Include <File.au3> $Window = "Untitled " opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() While 1 If WinExists($Window) Then MsgBox(32,"Window","Window is Active at " & _DateTimeFormat( _NowCalc(), 2)) TrayCreateItem("Window was active at " & _DateTimeFormat( _NowCalc(), 2));just for info Else ;?? Sleep(1000) EndIf $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $exititem ExitLoop EndSelect WEnd Exit Exit Any help would greatly be appreciated. http://www.kpunderground.com Link to comment Share on other sites More sharing options...
GaryFrost Posted February 3, 2006 Share Posted February 3, 2006 #include <Array.au3> #include <Date.au3> #Include <Constants.au3> #Include <File.au3> $Window = "Untitled " Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() $set_item = 0 While 1 If WinExists($Window) And Not $set_item Then $trayItem = TrayCreateItem("Window was active at " & _DateTimeFormat( _NowCalc(), 2));just for info $set_item = 1 ElseIf Not WinExists($Window) And $set_item Then $set_item = 0 TrayItemDelete($trayItem) EndIf $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $exititem ExitLoop EndSelect WEnd Exit SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Valuater Posted February 3, 2006 Share Posted February 3, 2006 (edited) it doesnt use that much on mine... but maybe this idea could help??? #include <Date.au3> #Include <Constants.au3> #Include <File.au3> $Window = "Untitled " opt("TrayMenuMode", 1); Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() AdlibEnable("Win_Exist"); you can set the time to wait While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $exititem ExitLoop EndSelect WEnd Exit Exit Func Win_Exist() If WinExists($Window) Then MsgBox(32,"Window","Window is Active at " & _DateTimeFormat( _NowCalc(), 2)) TrayCreateItem("Window was active at " & _DateTimeFormat( _NowCalc(), 2));just for info EndIf EndFunc 8) PS Gary got here first with a good idea, however i dont think he went for cpu useage ( he would know more on that than i would ) Edited February 3, 2006 by Valuater Link to comment Share on other sites More sharing options...
kpu Posted February 3, 2006 Author Share Posted February 3, 2006 Gafrost,Thanks for your fast response, but at idle it still is using the processor. Is it just my PC? Did you try and run it?Thanks, http://www.kpunderground.com Link to comment Share on other sites More sharing options...
kpu Posted February 3, 2006 Author Share Posted February 3, 2006 Thanks! That seems to do the trick. I guess I didn't see that command in the help. Then again, it been awhile since I've read through the latestet beta commands. Guess I need to do that more often! it doesnt use that much on mine... but maybe this idea could help??? #include <Date.au3> #Include <Constants.au3> #Include <File.au3> $Window = "Untitled " opt("TrayMenuMode", 1); Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() AdlibEnable("Win_Exist"); you can set the time to wait While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $exititem ExitLoop EndSelect WEnd Exit Exit Func Win_Exist() If WinExists($Window) Then MsgBox(32,"Window","Window is Active at " & _DateTimeFormat( _NowCalc(), 2)) TrayCreateItem("Window was active at " & _DateTimeFormat( _NowCalc(), 2));just for info EndIf EndFunc 8) PS Gary got here first with a good idea, however i dont think he went for cpu useage ( he would know more on that than i would ) http://www.kpunderground.com Link to comment Share on other sites More sharing options...
GaryFrost Posted February 3, 2006 Share Posted February 3, 2006 (edited) it does use a little, between 5 and 11 percent try the below, was between 0 and 2 percent #include <Array.au3> #include <Date.au3> #Include <Constants.au3> #Include <File.au3> $Window = "Untitled " Opt("TrayMenuMode", 1); Default tray menu items (Script Paused/Exit) will not be shown. TrayCreateItem("") $exititem = TrayCreateItem("Exit") TraySetState() $set_item = 0 While 1 $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $exititem ExitLoop Case Else If WinExists($Window) And Not $set_item Then $trayItem = TrayCreateItem("Window was active at " & _DateTimeFormat( _NowCalc(), 2));just for info $set_item = 1 ElseIf Not WinExists($Window) And $set_item Then $set_item = 0 TrayItemDelete($trayItem) EndIf EndSelect WEnd Exit Edited February 3, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now