QB64 Phoenix Edition
Auto relaunch of running program - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: Auto relaunch of running program (/showthread.php?tid=1345)



Auto relaunch of running program - Richard - 12-30-2022

Looking for suggestions...


With windows 22H2 (and similar) - various things just are not working like they used to - getting worse as time goes on.


Previously I could have a program run continuously for 3 days - now this does not seem to be possible.

I am looking for suggestions/ideas (that might work) to have a running program gracefully shut itself down and restart itself - the on-going log files generated by the program will assist in the restarted program continuing as if nothing had happened.

Various things I tried such as Task Scheduler and so appears to be unstable (because of Windows updates).


So, for example, program X starts off (manually run) - then say after 10 minutes (+/- 1 minute) it shuts itself down in a controlled manner, and then restarts itself.


RE: Auto relaunch of running program - SMcNeill - 12-30-2022

SHELL _HIDE _DONTWAIT "myprog.exe"   <-- to start a second instance of your program.
SYSTEM  <-- to shut down the current instance.


RE: Auto relaunch of running program - mnrvovrfc - 12-30-2022

Use "TIMER" function to keep track of how much time is being spent. Use "RUN" to launch another EXE file. But have you been doing this already? Oh no, if this is the case what else is M$ breaking in "Win-does-not One One"?

If you need to preserve data between runs of the same program that is yours, you'll have to save the data into a file so it could be read back on the next try, otherwise you're out of luck. "CHAIN" and "COMMON SHARED" aren't supported like 16-bit, there are too many security implications involved and some people like to do the sort of thing while online, that you're asking for.

You could still come up with a QB64 program that works as timer, to manage the "automatic" program runs but there's no control over the data sharing if you don't have the source code for the EXE file of the program you want to start and restart.

If you simply cannot have two instances of the same program, one trying to end its session while the other one is starting, then it's possible to check in memory for the program residing there but it requires strong Win API stuff. Maybe it's the same as in Linux, asking the program politely to finish, before starting a new session with it. Sometimes however the program refuses to finish because it hung up...


RE: Auto relaunch of running program - MasterGy - 12-30-2022

Hello!
I also used this for my latest game. The server program restarts every 10 minutes if no one connects. The reason is the same. After hours, the QB64 program crashes, even if we do not touch it.

I don't think it should be overcomplicated.

The example program restarts itself every 10 seconds, and you don't need to worry about defining the startup file.


Code: (Select All)
restart_time = 10 'restart sec



start_timer = Timer
Do: _Limit 10
    If Abs(Timer - start_timer) > restart_time Then Shell _DontWait Command$(0): System
Loop


I'm reading it now. SMcNeil already wrote the solution.