Program 1 time starting
Program 1 time starting
What is the best way to get a program not starting more than 1 time?
Re: Program 1 time starting
I mean at the same time.
Re: Program 1 time starting
Interesting question. Two things came to my mind:
A) Create/lock a file. If file exists or is locked, another instance of the program is running.
B) Check if the application exists in memory. Some OS calls are needed for this which probably makes it OS dependent (Windows/Linux).
A quick search gave me similar answers: Determine programmatically if a program is running
For Windows this popped up: Run single instance of an application using Mutex. But this is beyond my knowledge.
Edit: The same question in 2006: Mutex instances and related: Mutex Troubles [Solved]
A) Create/lock a file. If file exists or is locked, another instance of the program is running.
B) Check if the application exists in memory. Some OS calls are needed for this which probably makes it OS dependent (Windows/Linux).
A quick search gave me similar answers: Determine programmatically if a program is running
For Windows this popped up: Run single instance of an application using Mutex. But this is beyond my knowledge.
Edit: The same question in 2006: Mutex instances and related: Mutex Troubles [Solved]
Last edited by badidea on Nov 11, 2018 22:25, edited 1 time in total.
Re: Program 1 time starting
On Windows this is usually done using a named Mutex, as described in this article by Microsoft:
https://support.microsoft.com/en-us/hel ... n-visual-c
https://support.microsoft.com/en-us/hel ... n-visual-c
Re: Program 1 time starting
Tjanks for the reply's. I have made one by myself but I don't know if it is a good one:
Code: Select all
''Test if the program already is started
Dim aa As String
Dim tst1 As String
Dim tst2 As String
''This part at the begin of your program
Kill "existing.tst": Sleep 1200
Open "existing.tst" For Input As #1
Line Input #1, tst1
Close #1
If tst1 = "arrow" Then System
Open "existing.tst" For Output As #1
Print #1, "arrow"
Close #1
''Current loop in an existing program
Print "Press any key"
Do
Do
Print Timer; ' A function of the program
aa = InKey$: Sleep 3
If tst2 <> Left$(Time$, 8) Then
tst2 = Left$(Time$, 8)
Open "existing.tst" For Input As #1: Close #1
If Err Then
Open "existing.tst" For Output As #1
Print #1, "arrow"
End If
Close #1
End If
Loop Until aa <> ""
Loop Until InKey$ = Chr$(27)
Re: Program 1 time starting
Code: Select all
''A better way?
''Test if the program already is started
Dim aa As String
Dim tst1 As String
''This part at the begin of your program
Open "existing.tst" For Input As #1
Line Input #1, tst1
Close #1
If tst1 = "arrow" Then System
Open "existing.tst" For Output As #1
Print #1, "arrow"
Close #1
''Current loop in an existing program
Do
Do
Print Timer; ''An example function of the program
aa = InKey$: Sleep 3
Loop Until aa <> ""
Loop Until aa = Chr$(27)
Kill "existing.tst" ''This at the end of your program
End