Results 1 to 7 of 7

Thread: TASKLIST windows function

  1. #1

    TASKLIST windows function

    Hi All
    sometimes i test examples which does not exit correctly, and the thinbasic.exe still running in the background. i don't like going to task manager with ctrl+alt+del and then searching the long list for thinbasic.exe . so googling and i find the solution:
    http://superuser.com/questions/91478...ine-in-windows
    from the command prompt:

    TASKLIST /FI "IMAGENAME eq thinbasic.exe"
    tskill thinbasic


    look the picture below

    this is tested in windows xp/32. not sure if the same apply to windows 7 and above
    to test it run the first example here: http://www.thinbasic.com/community/s...p?11886-Mirage
    as it is before the later corrections. and exit it by clicking 'X' not by pressing ESC. try it 3 times so 3 instances of thinbasic.exe in the memory.
    thinbasic.JPG

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    What, what, whaaat?

    Are there any SampleScripts that do that for you? Let us know and we will have a closer look.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    It can happen when script has a Graphical User Interface (a window) and at some point there is an infinite loop.
    Even if the user is able to close the window, the script is still executing the infinite loop.
    It is good practice to always test, inside the infinite loop, if the main script window still exists.

    In console scripts, usually closing the console window automatically close the process.

    Anyway, any example showing the problem is welcome to try to find a fix.

    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

  4. #4
    Adding an explicit call to the ExitProcess(n) WinAPI (a kernel32.dll export), where n is the user-defined program exit code to be returned to the OS once the process is closed, to the program epilogue is an almost 100% foolproof method to achieve clean exit from a program of any complexity -- a multi-threaded application, a mixed GUI/CUI script, or an ordinary single-threaded GUI- or CUI-only program.

    The call may be included by the developer into their interpreter's internal at-exit routine, and/or it can also be duplicated by the user in their particular script as the final statement in the application closing sequence, in which case the effect will be achieved by whatever call of the two (user or internal) will actually occur the first.

    A rare case known to me that can still keep the interpreter core running is when the application spawns a sibling (not a child!) process, such as e.g. an MS Windows Help instance, via a call to ShellExecute() or ShellExecuteEx() APIs (shell32.dll exports) in the interpreter or user sources that would keep shell32.dll running despite the exit process request. In this case, it is advisable that a call to TerminateProcess() (yet another kernel32.dll export) be used instead of ExitProcess(n) in the end-user script, and/or the interpreter source code, and/or both, which is somewhat rougher but ensures the unconditional closing of all dependencies in the process to be terminated/aborted.
    Last edited by mike lobanovsky; 01-08-2016 at 21:38.
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

  5. #5
    the sample to let thinbasic.exe stay in memory is like this:
    Uses "ui"
    DWord hwin
    hwin=Canvas_Window("Canvas Test",1,1,640,480)
    While Not GetAsyncKeyState(27) 
    'While Not GetAsyncKeyState(27) And IsWindow(hwin)
    Canvas_Color(Rgb(255,255,255),0)
    Canvas_SetPos(160,10)
    Canvas_Print("test")
    Canvas_Redraw
    Wend
    Canvas_Window End
    
    click on 'X' and not pressing ESC key
    in fact i feel immediately that thinbasic.exe stay in memory from the some lag in closing the window.
    one day believe or not while doing too much testing and running too much scripts from other users i have about 10 thinbasic.exe until i begins to feel the system is too slow. naturaly i will press ctrl-del-alt to seel the list exe's
    while in the previous forum link Eros suggested using
    While Not GetAsyncKeyState(27) and IsWindow(hwin)
    but in many cases the users forgot to write the correct way to exit

    my solution is to make patch file such as remove.bat which have these lines
    TASKLIST /FI "IMAGENAME eq thinbasic.exe"
    tskill thinbasic
    pause


    fortunately tskill.exe will remove all instances of thinbasic , while if we use task mangaer it will end what we click on

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

    As you already described, to solve the problem, change While loop to something like:
    While Not GetAsyncKeyState(27) And IsWindow(hwin)
    ...
    Wend
    
    In this way loop exit condition is determined by not pressing Esc and hWin is still on screen.
    Without testing for the presence of the window, loop is still executing the While/Wend testing if Esc key is pressed.
    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

  7. #7
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    There is no one single solution to this situation.
    There could be many different windows on screen, some hidden some visible. Just closing one does not mean thinBasic has to assume script is finished.
    Or windows could be created from main loop only when some events occur and then close them on a timer event but main loop must still run.

    So, ... not easy to find a precise situation where the thinBASIC Core engine exactly knows when it has to shut down.
    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. [Q]: Function f() PTR?
    By ReneMiner in forum thinBasic General
    Replies: 3
    Last Post: 18-07-2013, 20:29
  2. The Great Windows 7
    By danbaron in forum Shout Box Area
    Replies: 2
    Last Post: 24-09-2011, 16:57
  3. Windows on Mac Pro
    By jack in forum Shout Box Area
    Replies: 0
    Last Post: 28-03-2011, 00:44
  4. Windows 95
    By JosephE in forum General
    Replies: 13
    Last Post: 10-09-2010, 03:21
  5. Windows API
    By Chris Holbrook in forum thinBasic General
    Replies: 2
    Last Post: 12-01-2009, 19:43

Members who have read this thread: 1

Posting Permissions

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