Duplicate Programs

ceaser

Active Member
Licensed User
Hi

I think this question has been asked before, but I cannot find the answer in the forum.

My question: how can I prevent a program from running twice on a PDA. There must be only one instance of a opened program on the PDA. If one has 2 copies of a program running on a PDA and one tries to access a Database, then the program comes up with an error message.

Thanks
Michael
 

ceaser

Active Member
Licensed User
Hi Agraham

Thanks for the reply. But I have a problem.:BangHead:

I have had feedbacks from surveyors in the field that the program gives them a "Database Locked" error message.

Now when you go to "Settings", then "Memory" and then tap on "Running Programs" one will notice that the name "Ceaser" appears twice there.

I think what is happening is that they go into the program and use one of the routines that uses the Design Database. Then on some or other way, they start a second copy of the program and try to use the same Design Database again. As the first copy of the program has opened the database, the second program cannot access the database and therefore generates the error.

Please help.:sign0085:

Thanks
Michael
 

ceaser

Active Member
Licensed User
Hi Erel

We are using the Workabout pro (Windows Mobile) from Psion.

Just a question. If I make a connection to a database (Con1.New) and I don't close it (Con1.Close) and I try to make a connection again, will a error be generated?

Thanks
Michael
 

ceaser

Active Member
Licensed User
Hi Erel\Agraham

I did a test now on my Recon (Windows Mobile) by tapping 3 times on the "Ceaser" icon and there were 3 copies of the program loaded!:sign0085::sign0085:

Thanks
Michael
 

linum

Active Member
Licensed User
Hello. I know my suggestion is not the best of the methods, and I do hope somebody else can post a concrete solution, but I have an app that at start up creates a CSV file named "ProgramON.csv" and when the program closes it renames that file to "ProgramOFF.csv". So you could possibly program a similar feature into your app and then add the following code to check if an instance of your program is already running as you start the program:

B4X:
Sub Globals
   'Declare the global variables here.

End Sub

Sub App_Start
   'Check to see if an instance of the program is already running   
    If FileExist(AppPath & "\ProgramON.csv") Then
        AppClose
    End If
   'Rename the ProgramOFF.csv to ProgramON.csv
    If FileExist(AppPath & "\ProgramOFF.csv") Then
      FileCopy(AppPath & "\ProgramOFF.csv", AppPath & "\ProgramON.csv")
      FileDel(AppPath & "\ProgramOFF.csv")
   End If
   
   'Your other code here
   
   Form1.Show
End Sub

Sub Form1_Close
   
   'Rename the ProgramON.csv to ProgramOFF.csv
    If FileExist(AppPath & "\ProgramON.csv") Then
      FileCopy(AppPath & "\ProgramON.csv", AppPath & "\ProgramOFF.csv")
      FileDel(AppPath & "\ProgramON.csv")
   End If
   
End Sub


Again, I hope there is a more elegant way of doing this but this is what I have been using and it works for me...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I did a test now on my Recon (Windows Mobile) by tapping 3 times on the "Ceaser" icon and there were 3 copies of the program loaded!
This is not the normal behavior of Windows Mobile.

@linum this solution is pretty problematic. If your program ends in some unexpected way (the user closed it with a task manager for example) the user will not be able to run it again.

You can use this library: http://www.b4x.com/forum/additional-libraries/384-useful-library-2.html#post2809 to see if a process is running.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…