B4J Question Prevent to open few instances of one app

bogdanc

Active Member
Licensed User
Longtime User
Hi All!

As it on the subject I wish to block opening multiply instances of one app.
 

bogdanc

Active Member
Licensed User
Longtime User
Hi Erel! I saw this discussion, but for me it dose not work. I used a Lunch4j to compile as exe but still I can run few instances.
 
Upvote 0

bogdanc

Active Member
Licensed User
Longtime User
If you want to get assistance then you need to provide more information.

You need to write what you tried and what happened. We cannot guess it...


Sorry Erel!
I was away from my PC so I could not post the code:

Code of main:

B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private fx As JFX
    Private splashForm As Form
    Private mainForm As Form
    Private t As Timer

    Private TabPane1 As TabPane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
 
 
     
  splashForm = Form1
  splashForm.SetFormStyle("TRANSPARENT")
  splashForm.BackColor=fx.Colors.ARGB(0,0,0,0)
  splashForm.RootPane.LoadLayout("splash") 'Load the layout file.
   'MainForm.RootPane.Style = "-fx-background-color: blue;"
'  MainForm.RootPane.Style = " -fx-background-color: transparent;"
   splashForm.Show
   t.Initialize("t", 1500)
   t.Enabled = True
    If ProcessCount("main22\.exe") > 1 Then
        Log("Only one instance of myApp allowed.")
        ExitApplication
    End If


End Sub

Sub t_Tick
   t.Enabled = False

  mainForm.Initialize("form2",700,700)
   mainForm.RootPane.LoadLayout("Main2") 'Load the layout file.
'
  Dim tp1 As TabPage =TabPane1.LoadLayout("START", "START")

'

   mainForm.Show
   splashForm.Close
End Sub


'count of number instances
Sub ProcessCount(ExeNamePattern As String) As Int
    Dim Count As Int = 0
    Dim Result As ShellSyncResult
    Dim sh As Shell
    sh.InitializeDoNotHandleQuotes("", "tasklist", Null)
    Result = sh.RunSynchronous(2000)
    If Result.Success = False Then Return Count
    Dim Match As Matcher  = Regex.Matcher2(ExeNamePattern, Regex.CASE_INSENSITIVE, Result.StdOut)
    Do While Match.Find
        Count = Count + 1
    Loop
    Return Count
End Sub


COde of splash:

B4X:
'Form2 class
Sub Class_Globals
   Private fx As JFX
   Private frm As Form
End Sub

Public Sub Initialize
   frm.Initialize("frm", 500, 500)
End Sub

Public Sub Show
   frm.Show
End Sub
 
Last edited:
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
I don't see anything wrong with your code, except
B4X:
Dim tp1 As TabPage =TabPane1.LoadLayout("START", "START")
which should raise and error.

I see in your second post that you are using launch4J, you can set it up to allow only one instance:
Capture.PNG
 
Upvote 0
Top