Relaunching program
Pages: 1 2
Alan Adams (2486) 1149 posts |
I’m not sure if this is possible. I have a number of programs (in BASIC) that work together. At one point I need one of them to re-initialise itself. Because the Init code includes DIMs as well as setting up variables, I can’t just re-run the INIT. Instead I thought I would arrange for the program to launch a copy of itself and then quit. While I got this to work, there is a problem in that these programs are coded so that two copies are not allowed to run simultaneously. The second copy will quit if there’s another copy running. So in this case the second copy quits, then the first one also quits. It does the check before the first Wimp_Poll. I need to launch the second copy after a delay, so that the launching program has time to quit before the second copy does its check. Options I’ve thought about are to delay the check until after polling loop starts – though I don’t know whether that is sufficient, or to create a relauncher application, that is given the name of the program to launch, and waits before doing so, either waiting until the original is no longer present, or for a time delay, or just until polling starts. Any suggestions (apart from re-writing the init code to separate the DIMs from the rest)? I’m trying to avoid that option, because the system uses a number of libraries, and they also have init routines, that set up DIMs. Changing those to have two separate inits, means changing all the programs that share the libraries, not just the one I need to re-init. |
Bryan (8467) 468 posts |
Maybe I have missed soomething, but my approach to this is ….
|
Chris Hall (132) 3559 posts |
If you Wimp_Initialise a task with the same name as an existing task, the previous one is automatically replaced. Simples. The Wimp looks after it all for you. If I run a second copy of !MultiTask or !Cat, it replaces the previous incarnation. |
Chris Evans (457) 1614 posts |
The two solutions above are probably much better than the one I thought of: |
Jon Abbott (1421) 2651 posts |
Make the DIM’s LOCAL inside a PROC/FN so they’re released when it exits back to your main loop:
|
Rick Murray (539) 13851 posts |
<shrugs> D’you really want me to post a screenshot with the iconbar full of copies of Edit? Each Wimp Initialise starts a new task. It doesn’t matter what the task is called. Furthermore, the idea of simply replacing tasks with the same name doesn’t make sense (unsaved data, etc). I think you’re mixing up task behaviour with module behaviour (which does replace, because There Can Be Only One in the RMA). |
Chris Hall (132) 3559 posts |
I think my comment was accurate. Some applications take special steps to have more than one icon bar icon when re-initialised. |
David J. Ruck (33) 1636 posts |
If only one copy of an application can be run, it’s because it’s specifically written to listen out for a wimp message indicating a new instance has started, and then immediately sending it a quit message. |
Steve Pampling (1551) 8172 posts |
I think it’s the other way round, some applications don’t take steps to ensure there is only one instance. |
Graeme (8815) 106 posts |
Instead of launching and quitting one of them, it seems you can use the RUN command in a BASIC program. That clears most variables and restarts. So DEF PROCrestart:RUN:ENDPROC may do the trick. Make sure you have finished everything before calling this. Also note that A% to Z% are not cleared by the RUN command so you can clear these yourself or use them to pass to the newly restarted program if needed. The CLEAR command can also be used. Again this does not clear A%-Z% but you would need to be careful where this is used. |
Alan Adams (2486) 1149 posts |
That’s pretty much what I’m doing.
I’ll check that one out – it sounds ideal. |
Rick Murray (539) 13851 posts |
It wasn’t, though. ;)
Fixed that for you. As I said, Wimp Initialise starts a new task. It doesn’t matter what the task is called. Any task for which only one copy can run is specifically doing that behaviour for itself. If anybody doubts this, feel free to throw together a dead simple Wimp program (or pick something simple like Edit or Calc 1) and just keep double clicking on the icon to load it…until all doubt is removed. 1 Does Calc still exist or is it just SciCalc these days? |
Bryan (8467) 468 posts |
I prefer CHAIN because it specifies the program by name allowing the program to be replaced by a new one (to fix bugs for example). I also use … SYS "Wimp_CloseDown",our_task%,!taskid%: PROCupgrade_data CHAIN("!RunImage") where I want the program to restart with upgraded facilities. A live HTTP server with new facities for example. I copied the idea from BT who use the same concept to upgrade telephone exchange software, whilst keeping calls going etc. |
Steve Fryatt (216) 2105 posts |
Indeed… most likely something like this (via this). |
Chris Hall (132) 3559 posts |
Oops! I thought it was a standard part of a multi-tasking program to listen out for message &400C2 and to quit if a task with the same name was being initialised but did not have the same task handle (i.e. it wasn’t being notified by itself). Example:
|
Steve Fryatt (216) 2105 posts |
Not as far as I know. It’s also backwards, because with the exception of developers who are testing software, users will generally expect the new instance that they unintentionally started up to back out from loading itself, and not the existing one that might have unsaved work, settings, calculations or whatever in it to exit without warning. |
Alan Adams (2486) 1149 posts |
this !! doesn’t let me delete a post. |
John WILLIAMS (8368) 495 posts |
but you can still edit it to delete the text and substitute the word “Deleted”. Still shameful, but to a lesser extent! But don’t delete anything anyone has replied to, or it’ll look very silly! |
Rick Murray (539) 13851 posts |
This. It’s the newly started one that ought to be looking to see if something is already there, and if so, quitting itself. Optional bonus, send some sort of message to the existing task to get it to show itself. Then the user rubbing the program will see it appear and not have to worry about what went on behind the scenes. |
John WILLIAMS (8368) 495 posts |
The sheer genie-us of it all? |
Rick Murray (539) 13851 posts |
;) Just automangle again. |
Matthew Phillips (473) 721 posts |
Going back to the original question, setting a system variable has been suggested. Another option is to use a command-line option, which avoids the need to delete the system variable. In this scenario the logic would work like this:
I think we implemented something like this in Nominatim, which can be used in a hidden manner, not appearing on the iconbar. If the user runs a second copy, the first task will reveal itself. |
Steve Fryatt (216) 2105 posts |
This can also be done without task-specific messages. PrintPDF does two things: 1. On loading, it does the same search through running tasks as described above for Launcher to see if there’s already an instance of PrintPDF present. If there is, then the copy that is in the process of loading quietly exits. 2. Once installed as a task, it listens for Message_TaskInitialise and on receipt, it checks to see if the initialising task is PrintPDF. If it is, it assumes that the initialising copy will correctly do as in point 1, and exit immediately. The installed task then opens its Choices dialogue. Taken together, this ensures that there is only ever one copy of PrintPDF running. It also ensures that if that copy is running without an iconbar icon, then the Choices dialogue can be opened by running PrintPDF a second time from a Filer window.
Using system variables for this is generally a very bad idea. It’s easy for something to go wrong and for the variable to remain in a state which no longer reflects the state of the associated application. The Task Manager’s state should always be in step with what applications are actually running. |
Stuart Swales (8827) 1357 posts |
I think this is suggested in the PRM but I can’t find it (haven’t looked too hard) but, as you say, it’s surely better to do as you describe for single-instance applications. |
David J. Ruck (33) 1636 posts |
Ensuring that the something hasn’t been left around from a failed run is tricky, you need to make sure an instance is actually still running, which would require looking through a task enumeration. Far, far easier is for the app to listen for task started messages which contains the name of the new task, and if it is the same, sent it a quit.
The advantage of my method is the existing task then knows what has happened immediately and can decide to bring itself to the front if appropriate. |
Pages: 1 2