Results 1 to 7 of 7

Thread: Kill a Timer immediately

  1. #1
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    52
    Posts
    248
    Rep Power
    40

    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??

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Kill a Timer immediately

    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    52
    Posts
    248
    Rep Power
    40

    Re: Kill a Timer immediately

    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

    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

    Martin

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Kill a Timer immediately

    Quote Originally Posted by martin
    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
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    52
    Posts
    248
    Rep Power
    40

    Re: Kill a Timer immediately

    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

  6. #6
    Member
    Join Date
    Mar 2009
    Location
    Netherlands
    Age
    52
    Posts
    248
    Rep Power
    40

    Re: Kill a Timer immediately

    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.

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Kill a Timer immediately

    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.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. Schools kill creativity
    By Charles Pegge in forum Shout Box Area
    Replies: 3
    Last Post: 21-11-2010, 00:09
  2. An internet kill switch?
    By LanceGary in forum Shout Box Area
    Replies: 2
    Last Post: 22-06-2010, 06:29

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •