View Full Version : Kill a Timer immediately
Guys I need some advice
I have a script with a Timer function. In this function is a lot of code and also calls to other functions (and in those other functions are also function calls).
When the user click a STOP button the Timer must be killed immediately and all remaining commands in the timer-function(s) must be ignored. I already added DIALOG KILL TIMER but then the script still want to finish all commands in the timer function and then it will be killed. That's not what I want.
Is there a smart way to do this? Ofcourse i can add IF NOT %TERMINATE THEN before each line but I don't think that's a nice solution. Any tips??
ErosOlmi
24-06-2009, 20:51
One way is the one you described: many if ... then
Onother could be to divide your main function into different smaller functions and start each of that functions with an IF <timer is active> then ...
I think this request is enough interesting to spend some time and think more if such a situation can be managed nativelly by thinBasic. I mean, something like (I'm just brainstorming):
FUNCTION MyFunction(...) AS <retruntype>... ExitIf <test>
and during execution of function thinBasic will continue test if <test> if true and if yes, than exit.
Of course if MyFunction calls another function not having a similar test the second function will be executed entirely.
But I'm open to any more clever idea
Ciao
Eros
Hello Eros,
One way is the one you described: many if ... then
Onother could be to divide your main function into different smaller functions and start each of that functions with an IF <timer is active> then ...
I did that, but now I discovered that when I change the value of a global variarable, it still keeps it old value in the timer-function(s).
I think this request is enough interesting to spend some time and think more if such a situation can be managed nativelly by thinBasic.
Well it was not really a request, but ofcourse I would be very happy if you create something for this in Thinbasic :D
I mean, something like (I'm just brainstorming):
FUNCTION MyFunction(...) AS <retruntype>... ExitIf <test>
and during execution of function thinBasic will continue test if <test> if true and if yes, than exit.
I think that an elegant, great and brilliant solution!!
But I'm open to any more clever idea
I can't imagine there are better solutions ;) Well, let's see what will happen :lol:
Martin
ErosOlmi
25-06-2009, 08:12
I did that, but now I discovered that when I change the value of a global variarable, it still keeps it old value in the timer-function(s).
I suppose the fact thinBasic is single thread, global variable value is set only when the timer function finish its execution so the next event (I think your STOP button) can occurs.
I need to think how I can introduce multi-threading in thinBasic but for sure not now and not before I finish thinBasic 1.x line version (still almost compatible with Win9x systems) and move to 2.x line version (compatible only with WinXP or above)
Ciao
Eros
I suppose the fact thinBasic is single thread, global variable value is set only when the timer function finish its execution so the next event (I think your STOP button) can occurs.
Okay for now I think I can solve this problem by saving a variable to a file and then read it in the timer function.
I need to think how I can introduce multi-threading in thinBasic but for sure not now and not before I finish thinBasic 1.x line version (still almost compatible with Win9x systems) and move to 2.x line version (compatible only with WinXP or above)
I would love to see this in 2.x version of ThinBasic, I think it's a very friendly feature (and probably unique comparing to other languages).
Have a nice day!
Martin
I suppose the fact thinBasic is single thread, global variable value is set only when the timer function finish its execution so the next event (I think your STOP button) can occurs.
Today I tried again to terminate with a global boolean variable and now it IS WORKING. I don't know what I did wrong a few days ago.
ErosOlmi
26-06-2009, 15:49
To be ... :?: honest I had some doubts regarding possibility to do what you wanted to do but I didn't had time to produce an example.
Well, that's good news.