B4J Question [SOLVED] Restart program (here B4J)

Discussion in 'B4J Questions' started by GMan, Apr 17, 2019.

  1. GMan

    GMan Well-Known Member Licensed User

    Is it possible to auto-restart an B4J-programm ?
     
  2. Cableguy

    Cableguy Expert Licensed User

    I would say so, create a batch file on the app-finished event and call it...
     
    GMan likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    You can create another program that starts the first program after 1-2 seconds. Start the second program with jShell and call ExitApplication.
     
    GMan likes this.
  4. GMan

    GMan Well-Known Member Licensed User

    Done - works fine :)

    Depending on jShell and @Erel 's sample i used this in both parts, here the "Re-Starter"

    Code:
    Sub Process_Globals

    End Sub

    Sub AppStart (Args() As String)
        
    Dim shl As Shell
        
    Try
            shl.Initialize(
    "shl""java.exe" , Array As String("-jar""Your.jar"))
            shl.WorkingDirectory = 
    File.DirApp
            shl.Run(-
    1)
        
    Catch
            
    Log(LastException.Message)
        
    End Try
    End Sub

    Sub shl_ProcessCompleted (Success As Boolean, ExitCode As Int, StdOut As String, StdErr As String)
        
    If Success Then
            
    Log(StdOut)
        
    End If
    End Sub


    'Return true to allow the default exceptions handler to handle the uncaught exception.
    Sub Application_Error (Error As Exception, StackTrace As StringAs Boolean
        
    Return True
    End Sub
     
    Kiffi likes this.
  5. GMan

    GMan Well-Known Member Licensed User

    For all:
    here the part from the Program that should be restartet.

    Put the code in any event you like, i.e. Sub ExitButton_Click:
    Code:
    Sub ExitButton_Click
       
        
    Dim sf As Object = xui.Msgbox2Async("Proggi wird neu gestartet !","Neustart","OK","","Abbruch"Null)
        
    Wait For (sf) Msgbox_Result (Result As Int)
        
    If Result = xui.DialogResponse_Positive Then
            
    Dim shl As Shell
            
    Try
                shl.Initialize(
    "shl""java.exe" , Array As String("-jar""YourRestart.jar"))
                shl.WorkingDirectory = 
    File.DirApp
                shl.Run(-
    1)
            
    Catch
                
    Log(LastException.Message)
            
    End Try
            
    Log("Neustart!!!")
               
            
    ExitApplication
        
    End If
    End Sub
     
    Peter Simpson likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice