Time-based Event?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
NancyM
Pro Scripter
Posts: 66
Joined: Mon Jul 18, 2016 7:01 pm

Time-based Event?

Post by NancyM » Tue Sep 13, 2016 5:05 pm

Is there any way to set a timeout threshold for, let's say 90 seconds, and then when that 90 seconds is up, transfer control to an event handler? Kind of like the OnEvent, but time-based?

I was thinking that would be a way to see if I've gotten stuck somewhere with some unanticipated condition I haven't handled.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Time-based Event?

Post by JRL » Wed Sep 14, 2016 4:03 am

Perhaps a custom OnEvent> timer? This counts for ten seconds then the result subroutine resets everything to start counting for another ten seconds and so on. All very pointless but time is handled.

Code: Select all

Let>TimePeriod=10
Timer>StartTime
OnEvent>Custom,EventTimer,TimedOut,ResultEvent

Message>
Let>Count=0
Label>Loop
  Wait>0.1
  Add>Count,1
  SetControlText>Macro Scheduler Message,TMemo,1,Count
Goto>Loop

SRT>EventTimer
  Timer>EndTime
  Let>TotalTime={(%EndTime%-%StartTime%)/1000}
  If>%TotalTime%>%TimePeriod%
    Let>TimedOut=True
  EndIf
END>EventTimer


SRT>ResultEvent
  Let>TimedOut=
  MDL>We reached %count% in %TimePeriod% seconds
  Let>Count=0
  Timer>StartTime
  Message>
END>ResultEvent

NancyM
Pro Scripter
Posts: 66
Joined: Mon Jul 18, 2016 7:01 pm

Re: Time-based Event?

Post by NancyM » Wed Sep 14, 2016 6:46 pm

Hmmm... maybe, although I wonder what that'd do to performance if, as the docs describe, it executes continuously. Does it allow the rest of the program to run?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Time-based Event?

Post by JRL » Wed Sep 14, 2016 7:04 pm

OnEvent>s, used prudently, hardly have any effect on performance. You want to keep custom event test subroutines as small as possible and you don't want to test for a lot of different files or windows with the FILE_EXISTS or WINDOW_OPEN event handlers. But... this particular OnEvent is not likely to be noticeable

NancyM
Pro Scripter
Posts: 66
Joined: Mon Jul 18, 2016 7:01 pm

Re: Time-based Event?

Post by NancyM » Thu Sep 15, 2016 5:20 pm

Thanks! I will give it a shot.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts