Timer with Menu / button options

Timer with Menu / button options

Postby TimStone » Mon Jun 25, 2012 9:53 pm

I've been looking at various threads here about timers. I haven't seen what I want to do, so maybe somebody has some ideas on this.

I have a "utility application" that does a series of tasks every six hours. The rest of the time it sleeps. It runs on a server and is usually not in view.

What I want to do is create a window with menu items that let me "force an update", "view the log", and "exit". In addition, I want to have it run the subroutine every six hours.

The issue is the menu items must be clickable while the timer is running, and allow those functions to be called.

Has anyone worked with this who might know of some sample code ?

Thanks

Tim
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Timer with Menu / button options

Postby Antonio Linares » Tue Jun 26, 2012 1:49 am

Tim,

This example counts a minute. If you replace 60 with ( 60 * 60 * 6 ), then it will count six hours:

Code: Select all  Expand view
#include "FiveWin.ch"

function Main()

   local oWnd

   DEFINE WINDOW oWnd TITLE "Counting minutes"

   ACTIVATE WINDOW oWnd ;
      ON INIT BuildTimer()

return nil

function BuildTimer()

   local oTmr, nStart := Seconds()

   DEFINE TIMER oTmr INTERVAL 1000 ;
      ACTION If( Seconds() - nStart > 60, ( nStart := Seconds(), MsgInfo( "a minute" ) ), )

   ACTIVATE TIMER oTmr

return nil
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42089
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Timer with Menu / button options

Postby TimStone » Tue Jun 26, 2012 4:13 pm

I did figure that out yesterday ... at first I thought the number was in seconds, but interval measures thousands of a second according to the documentation.

Originally I used 21600 for 6 hours, but it was running the function called every 21.6 seconds !

From the online doc:
<nInterval> Defines the timer interval in thousandths of seconds.


Can you please confirm this ?
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Timer with Menu / button options

Postby Antonio Linares » Tue Jun 26, 2012 7:02 pm

Tim,

Yes, milliseconds:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms644906(v=vs.85).aspx

thats why I used 1000 when creating the timer, to fire the action every second. It would be better a wider interval so the app manages less events
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42089
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Timer with Menu / button options

Postby TimStone » Tue Jun 26, 2012 7:11 pm

Got It ! I set the interval to the total time ... will change it to your example. Thanks
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Timer with Menu / button options

Postby TimStone » Wed Jun 27, 2012 7:05 pm

OK ... I worked this out but for anyone else who has an issue.

IF your timer will go for longer than the current day, do not use Seconds( ). By default it resets to 0 at midnight.

Instead I used ElapTime( ) which will take into account when a day changes, and keep right on working !
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 110 guests