mexykanu Posted February 3, 2009 Share Posted February 3, 2009 Hello, I'm having trouble using a timer for my program. It should work as follows: - a function is ran once every X minutes (user defined) - the program should still be available for interacting - ONLY by System Tray, using TrayGetMsg. I don't need to use TimerInit because the program runs at 100%. Thanks, mexykanu. Link to comment Share on other sites More sharing options...
BrettF Posted February 3, 2009 Share Posted February 3, 2009 Post your code, we aint no mind reader. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
mexykanu Posted February 3, 2009 Author Share Posted February 3, 2009 #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 $dif=TimerDiff($start) $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $aboutitem Msgbox(64,"About:","AutoIt3-Tray-sample") Case $msg = $exititem ExitLoop EndSelect WEnd Exit Func _givemsg() MsgBox(0,"","msg") EndFunc Hi again. Here's a sample code. I want to run _givemsg() every 2 minutes. Thanks, mexykanu. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2009 Moderators Share Posted February 3, 2009 mexykanu, You are not using TimerDiff correctly. This will do what you want:expandcollapse popup#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() $start = TimerInit() While 1 If TimerDiff($start) > 2 * 60 * 1000 Then _givemsg() $start = TimerInit() EndIf $msg = TrayGetMsg() Select Case $msg = 0 ContinueLoop Case $msg = $aboutitem Msgbox(64,"About:","AutoIt3-Tray-sample") Case $msg = $exititem ExitLoop EndSelect WEnd Exit Func _givemsg() MsgBox(0,"","msg") EndFunc This will restart the 2 minute delay from the moment you close the message box. If you want the box to open exactly 2 minutes after the last time it opened, just place the new TimerInit line above the function call. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrettF Posted February 3, 2009 Share Posted February 3, 2009 Its not your full code, so I can't know everything about it... But try this netherless: #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() $start = TimerInit () While 1 $dif = TimerDiff($start) ;If $dif >= 2*1000*60 Then; SHould be 2 minutes if my calculations are correct... Otherwise i'm testing with 5 seconds If $dif >= 5000 Then _givemsg () $start = TimerInit () EndIf $msg = TrayGetMsg() Select Case $msg = $aboutitem MsgBox(64, "About:", "AutoIt3-Tray-sample") Case $msg = $exititem ExitLoop EndSelect WEnd Func _givemsg() MsgBox(0, "", "msg") EndFunc ;==>_givemsg Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version! Link to comment Share on other sites More sharing options...
mexykanu Posted February 3, 2009 Author Share Posted February 3, 2009 (edited) Thank you melba and brettf, that worked although i don't know why my code used the processor at 100%. Edited February 3, 2009 by mexykanu Link to comment Share on other sites More sharing options...
weirddave Posted February 3, 2009 Share Posted February 3, 2009 Thank you melba and brettf, that worked although i don't know why my code used the processor at 100%.You're looping round without taking a break, use Sleep(100) somewhere in the while loop to free up the cpu. Link to comment Share on other sites More sharing options...
mexykanu Posted February 3, 2009 Author Share Posted February 3, 2009 You're looping round without taking a break, use Sleep(100) somewhere in the while loop to free up the cpu.That's what i used when i tried first, but it puts the whole program to sleep. I need it always active so i can right-click the icon in the systray . Anyway, the problem was solved. Many thanks to everyone Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2009 Moderators Share Posted February 3, 2009 weirddave,There is no need to use a Sleep when using the GUIGetMsg or TrayGetMsg functions - from the Help file for both functions:RemarksThis function automatically idles the CPU when required so that it can be safely used in tight loops without hogging all the CPU.Adding a Sleep just makes the whole loop very unresponsive - as mexykanu found. :-)M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
weirddave Posted February 3, 2009 Share Posted February 3, 2009 Interesting, I must admit, I'm not too familiar with GUI and Tray functions. I find a small sleep does often help stop loops hogging the cpu tho even if it's just 1ms to keep it nice and responsive. Obviously not much help in this case.... 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