Check if a application was running

newbie

Member
Licensed User
Longtime User
Hi,

is there a possibility to check if a program was running or not ?
I want to make that the Application can't start two or more times.

kind regards from germany
Gerd
 

specci48

Well-Known Member
Licensed User
Longtime User
Hello Gerd,

as far as I know this can't be done in a simple way. :sign0013:

The "workaround" is to read all the running/active processes (with GetProcesses from the useful library of dzt) and search for the own filename in the returned table.


specci48
 

pinoy_ako

Member
Licensed User
Longtime User
hi erel,

but why my program set to run at power up, runs at multiple instance? program is running like, 3 or more times at the same time on power up.
 

newbie

Member
Licensed User
Longtime User
Multiple Instance

Hi Erel,

that is not correct.

My App. run on a MDE Device with CE 5.0
it is no Problem to start and run two or more instances.
Only the there is not enough memory i get a Error.

Gerd
 

pinoy_ako

Member
Licensed User
Longtime User
hi erel,

does it really have to show error like "not enough memory" if a program is set to run at start up? i have that same error. but if i just run the program manually, no error like that.

thanks
 

pinoy_ako

Member
Licensed User
Longtime User
i still dont have a license. im just trying to develope a program for may bluetooth enable hardware.

thanks
 

HARRY

Active Member
Licensed User
Longtime User
Erel,

I wonder whether it is (still) true that on the device a program can only be started once.
I run Windows 6.1 on my device and I can easily start two occurrences of the same program.

I did this accidentely by tapping twice the program name on the Start menu (impatient!). One occurrenc ran into problems because it tried to delete a file which was in use by the other occurrence.

I tried to avoid that problem using the following code in AppStart:

If cPPC=True Then
Runs=0
ProcArr()=dzHW1.GetProcesses
For i = 0 To ArrayLen(ProcArr()) -1
If StrToUpper(ProcArr(i))=StrToUpper("MyProgram.EXE") Then
Runs =Runs+1
End If
Next i
End If
If Runs > 1 Then
Msgbox("MyProgram runs already. This occurrence is closed.",cMsgboxOK,cMsgboxExclamation)
AppClose
End If

Unfortunately this doesnt work. I think that the processes are created so fast and it takes so long to really start the program, that both occurrences find out that the program is already running.

I use a downloaded, flashed version of Windows Mobiule 6.1 on my device, but I can hardly think that that is the cause of this 'problem'.

Please comment.

Harry
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Windows Mobile should allow only one instance of your application to run.
When you start a running program, it should become focused instead of creating another process. This is not handled by Basic4ppc but rather by the OS.
I think that the problem only occur when your application starts. You can create a small program that launches your full program (and waits till it closes).
This launcher program will load quick and hopefully the OS will succeed in forcing only one instance of it.
 
Top