Announcement

Collapse
No announcement yet.

Restarting a program...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fim Wästberg
    replied
    AlwaysUp

    Somtimes http://www.coretechnologies.com/products/AlwaysUp/ can be used
    /Fim W

    Leave a comment:


  • Michael Mattias
    replied
    Well, I was working on the semaphore version of this over the weekend.

    I got it to work for this application, but I decided that using a semaphore for this application was silly and a mutex would be superior.

    So let me change my recommendation to "I really like the mutex for this application."

    FWIW, it's pretty simple..
    Code:
    $MUTEX_NAME = "something"
    FUNCTION PbMain() AS LONG
    
      hMutex  = CreateMutex(..._, $MUTEX_NAME) 
      iWait = WaitForsingleObject (hMutex, %INFININTE)
      IF iWait = %WAIT_OBJECT_0 THEN
         CALL MainProcedure  (params, bRestart)  ' set restart flag in this proc if wanted
         IF ISTRUE bRestart THEN
             ' execute ourself ansynchronously
             GetModuleFileName BYVAL %NULL, szProgram, SIZEOF(szProgram) 
             X = SHELL (szProgram) 
             
        END IF
      ' release ownership of the mutex
       ReleaseMutex hMutex
    
     ELSE
      ' handle WFSO errors 
     END IF
    
    ' --------------------------------------------------------------
    ' Two schools of thought here at the end of WinMain:  
    ' A. Thou shalt release that which you obtain
    ===>   CloseHandle hMutex
    ' B. Allow Windows to close the process' open handle to the mutex, since 
    ' it will only do so when the current process is TOTALLY "ended" so the new instance
    ' of the program can only obtain ownership when the the Wicked Witch of the West 
    ' is "really, really, truly dead"
    ==>  DO NOTHING ====
    
    END FUNCTION  ' Pbmain
    Oh, well, at least the exercise gave me some ideas for a decent semaphore demo...

    MCM

    Leave a comment:


  • Michael Mattias
    replied
    Well, if you really want to 'wait for something' before allowing the new instance of the program to start actually doing something...

    .. as soon as you see "wait for something" you should be thinking synchronization objects, not timers. (Didn't we just have this discussion here?)

    Have your program as its first step wait on obtaining ownership of a named mutex or semaphore... the new instance cannot obtain that ownership until the prior instance has completely ended and the O/S has deleted the object by closing all its open handles.

    (I like the semaphore here... no creation/destruction timing issues to deal with).

    Memory is not an issue... each new process gets its own 2 Gb user space, and as long as you have sufficient RAM+free disk the new instance will start just fine.

    Trying to mess with the swap file is a fool's errand... let Windows handle it, that's what operating systems are designed to do.

    MCM

    (Afterthought: Wouldn't this make a great demo for semaphores, where we currently have no demos? I think I'll do that).
    Last edited by Michael Mattias; 2 Apr 2008, 10:55 AM.

    Leave a comment:


  • Erich Schulman
    replied
    The program might need a moment for the disk cache to be flushed etc. You could start a batch file that pauses x seconds (duration taken as a command line parameter) then calls your program. Or call another instance of your program and use a parameter to specify a sleep duration. After either, exit the original.

    I would really prefer PB provide a restart mechanism. PB can then keep a certain amount of memory allocated to guarantee the swap file cannot shrink and regrow between the exit and restart.

    Leave a comment:


  • John Gleason
    replied
    I've done it with the SHELL function:
    Run an executable program asynchronously (as a separate process), while execution of the original application continues uninterrupted
    Then exit the 1st program normally.

    Leave a comment:


  • Mel Bishop
    started a topic Restarting a program...

    Restarting a program...

    ...without exiting and clicking the icon again.

    I'm writing a program and there are occasions when I need to clear all variables and start the program fresh.

    Under PB/DOS, all I needed to do was CLEAR and RUN. Can't do that in CC.

    I've looked the help files and the forums but can't seem to find what I'm looking for or maybe I'm just looking for the wrong key word(s).

    Any help out there?
Working...
X
😀
🥰
🤢
😎
😡
👍
👎