1. Luiz Marques
  2. PowerBuilder
  3. Thursday, 22 November 2018 09:51 AM UTC

Hello Everyone,

              I'm working on an application using powerbuilder 2017 R3 and I need to use the timing object to run a specific process every X seconds. This application do not have a window and because of that I'm using the timing object rather than the window timer.. On the application open script I created a timing object instance like below, but the timer event on the timing object was never triggered.

iu_timing_batch = CREATE u_timing_batch 

u_timing_batch.start(10) --I would expect that every 10 seconds run the scripts on the timer event on the timing object until I "stop" the timer 

 

Anyone have already worked with timing object in an application without window and could give some advise on how to do that ? 

Luiz Marques Accepted Answer Pending Moderation
  1. Monday, 26 November 2018 09:15 AM UTC
  2. PowerBuilder
  3. # 1

Thanks everyone that replied my doubt..... Unfortunately they want to remove all ui (window, etc) ...... I'm using the sleep function that leaves the nvo alive until the do not call the sleep again.....That the solution that I find and that is working how the client expect....

Comment
There are no comments made yet.
Brad Mettee Accepted Answer Pending Moderation
  1. Friday, 23 November 2018 20:42 PM UTC
  2. PowerBuilder
  3. # 2

Hi Luiz,

You may not need a timer object. We've used code like this in the past.

// external declarations:
// pause application for N milliseconds, allowing windows to continue doing other things
Subroutine WinSleep(long MSec) library "KERNEL32.DLL" alias for "Sleep"

// instance vars
datetime idt_endtime

// app open

idt_endtime = datetime(Today(), it_endtime) // based on your script, it_endtime is set elsewhere

do while datetime(today(), now())
  this.event ue_process()
  winsleep(5000)

  do while yield()
  loop
loop
// clean up follows

This will call ue_process, then wait 5 seconds before calling it again, regardless of how long ue_process may take.

If you want it to be called every 5 seconds, post the ue_process event. Then, in ue_process, check/set an ib_busy variable so you don't start the processing again while it's already running. 

By putting this code in the app open even, you force the application to stay running until the time is up and the loop exits.

Comment
  1. Luiz Marques
  2. Friday, 23 November 2018 21:22 PM UTC
Thank you very much... I used the powerbuilder sleep function and works properly... But the client I don't know why is asking me to use the timing object... I was just curious about the timing object... I already generated the executable and it's running and doing what have to do... But I'm afraid of the client asking about the timing object... It's a very simple batch that I had to convert to remove the ui (window)... So I moved all the events from the window to a nvo... Let's see what the client say about the sleep... ?
  1. Helpful
There are no comments made yet.
Luiz Marques Accepted Answer Pending Moderation
  1. Friday, 23 November 2018 17:24 PM UTC
  2. PowerBuilder
  3. # 3

Hello Chris,

             Thanks for your reply. I had a look in to the timing object and now I understood a bit better how it's works but not 100%. I create a timing object  (ns_timing_master, exactly the same), registered a non visual object (uo_batch_ancestor) and the event (to be called). In the example below, the ue_process is called the first time...... How this same event can be called every five seconds ?

constructor event uo_batch_ancestor - create the timing object

IF IsValid (io_timer) = TRUE THEN // YES=>Timer Instantiated?
io_timer.start( 5 ) // YES=>Start Timer
else
io_timer = CREATE uo_timing_master // NO=>Create Timer
io_timer.of_register( THIS, "ue_process" ) // Register Timer
io_timer.start( 5 ) // Start Timer
END IF

 

ue_process event uo_batch_ancestor

DateTime dt_endtime_today
Long ll_ret
//First we stop the timer during the process execution.
io_timer.stop()
idt_now = DateTime(Today(),Now())
dt_endtime_today = DateTime(Date(idt_now),it_endtime) //This is the datetime where the program is supposed to stop today.
it_now = Time(idt_now)
IF (Time(idt_now) > it_endtime AND Not(idt_started > dt_endtime_today)) THEN
//Don't process, but still running in background
Return 1
ELSE

IF il_interval <= 0 THEN
RETURN -1;
ELSE
//OK, let's call the job.
This.Event ue_batch()
This.of_heartbeat()
This.of_next_run( )
END IF

END IF

My timing object is not triggering the event ue_process evety 5 seconds..

of_next_run function uo_batch_ancestor

IF IsValid (io_timer) = TRUE THEN // YES=>Timer Instantiated?
io_timer.start( il_interval ) // YES=>Start Timer
else
io_timer = CREATE uo_timing_master // NO=>Create Timer
io_timer.of_register( THIS, "ue_process" ) // Register Timer
io_timer.start( il_interval ) // Start Timer
END IF

How can I keep the non visual object that I created the timing object alive waiting for the event to be triggered ? My application is closing after run the first time the ue_process. Should I call the timer event?

Comment
  1. Brad Mettee
  2. Friday, 23 November 2018 20:33 PM UTC
see full answer above (comment block ate half my post)
  1. Helpful
  1. Luiz Marques
  2. Friday, 23 November 2018 21:28 PM UTC
Hi Chris,

The timer restart in the function of_next_run



IF IsValid (io_timer) = TRUE THEN // YES=>Timer Instantiated?

io_timer.start( il_interval ) // YES=>Start Timer

else

io_timer = CREATE uo_timing_master // NO=>Create Timer

io_timer.of_register( THIS, "ue_process" ) // Register Timer

io_timer.start( il_interval ) // Start Timer

END IF



But after restart the timer the user object do not wait the timer, keeps going and the application closes...
  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 23 November 2018 21:43 PM UTC
Note that you will need an invisible Window open i order to keep your NVUO instantiated. If any PB App does not open at least one window - the O/S will close it after the last script is executed.
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 23 November 2018 16:09 PM UTC
  2. PowerBuilder
  3. # 4

Hi Luiz;

   The Timing object is working well for me in PB2017R3 and even for the past two decades in earlier releases of PB from Sybase. It also works well in PowerServer Web and PowerServer Mobile Apps as well. Its a little bit tricky though to implement as you need to create a descendant of the Timing object class that implements what to do when the timer event fires. Typically, that means firing a corresponding event on the requesting object class.

   You can see a full implementation of the Timing Class in the STD Integrated and Web Service frameworks. If you like, try downloading the OrderEntry example application and have a look at its use of the ns_timing_master descendant class in the example App & associated framework.

HTH

Regards ... Chris

Comment
There are no comments made yet.
Luiz Marques Accepted Answer Pending Moderation
  1. Thursday, 22 November 2018 10:35 AM UTC
  2. PowerBuilder
  3. # 5

Thank you very much for you quick reply. It was what I thought ...... We need something to keep the application alive (or a hidden window, that is what I prefer, or this loop with a timer or a variable that say "the timer still running)...........

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Thursday, 22 November 2018 10:12 AM UTC
  2. PowerBuilder
  3. # 6

Powerbuilder applications stop automatically if you don't open a window in applications open event. How do you keep your application running?

Maybe you application runs in a loop so it can't execute the timer event?

 

Here is a simple code for application open event that works:

n_cst_timing lnv_timing

long ll_cpu

// start timer

lnv_timing = CREATE n_cst_timing

lnv_timing.start(10)

// run a loop for 30 seconds before the open events ends and application closes

ll_cpu = cpu()

do while cpu () - ll_cpu < 30000

    // yield to have time to execute events

    // without this yield the timer event will not execute because of this loop

    yield()

loop

DESTROY lnv_timing

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.