B4J Question Detect a Previous Instance of a running B4J App

aminoacid

Active Member
Licensed User
Longtime User
Is that any way to detect if a previous instance of a B4J App is running?

In VB6, you could do this with "If App.PreviousInstance then ......"

Just wondering if there is something similar in B4J, or a way to determine if the JAR file is already in execution.

Thanks!
 

Dadaista

Active Member
Licensed User
Longtime User

Post #4
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User

Post #4

Thanks for the pointer to the Post. Don't know how I missed that!
Great ideas!
I was hoping for a more elegant/simple solution but it looks like there isn't any. I think for now I'll go with the UDP socket technique.
Tx again.
 
Upvote 0

aminoacid

Active Member
Licensed User
Longtime User
I took rraswisak's code and wrote it as a Sub so it could be used in a manner similar to the VB6 " App.PreviousInstance" feature:

B4X:
Sub AppPreviousInstance As Boolean
    Private xInstance As UDPSocket                     '<--- from jNetwork library
    Try
        xInstance.Initialize("",12340,0)             '<--- change the unique port as you want
        Return(False)
    Catch
        Return(True)
    End Try
End Sub

B4X:
If AppPreviousInstance Then
        fx.Msgbox(MainForm, "Application already running !","Attention")
        ExitApplication
 End If

Thanks rraswisak!
 
Upvote 0
Top