PDA

View Full Version : TB Main - automatically be terminated after number of seconds



M30_NXG
03-03-2020, 13:57
Hi there,

Is there any idea, how to realize an TIMEOUT function
like demonstrated by the short VBS code below?

Purpose: detect eventually "hang up" or "endless" code execution.

VBS Code:
----------

WScript.Timeout = 2
WScript.Echo "Starting Script"
WScript.Sleep 5000
WScript.Echo "Ending Script"

Output:
-------

Starting Script
Script execution time was exceeded on script "C:\test.vbs".
Script execution was terminated.

See here:
https://www.devguru.com/content/technologies/wsh/wscript-timeout.html

Tx

Ben

DirectuX
03-03-2020, 14:53
Hi Ben,

the example you provided rely on event,
you can achieve this with DIALOG SET TIMER (https://www.thinbasic.com/public/products/thinBasic/help/html/dialog_set_timer.htm).
for usage, see samples :\thinBasic\SampleScripts\UI\CallBacks\_TBGL\TBGL_Control2_TimerC.tbasic or \thinBasic\SampleScripts\UI\Timer\Timer_Sample.tBasic

For a console script, you would have to check regularly the elapsed time (https://www.thinbasic.com/public/products/thinBasic/help/html/timing.htm) (i.e. inside a loop)
Edit: Though, in this case, the 'check' may not catch an endless code execution if not well placed.

ReneMiner
07-03-2020, 01:46
IT has more than just the windows-timer. For example to core built-in Hires-timer that is able to measure fractions of microseconds, or even the common cTimer-class. If that's not enough then there is the ordinary GetTickCount but that's only good above 150ms. Dialog Set Timer is pretty much the same, not very accurate and it can happen the timer will not call back on time.

And I have also a question about some undocumented module iType ... What does it do? How to access it? I discovered 2 more functions in filemodule - not documented neither Disk_Size("c:\") and Disk_Free("d:")...
And I found an interesting keyword cLoadOCX but no documentation about it. Is it a class or just a subelement of a built-in UDT? Can it load customizs ActiveX controls? Or is there a way to do so?